From 6a768905a6b9d48da1ac95babc0cd4a01f4c70f0 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 18 Nov 2020 18:04:06 -0500 Subject: [PATCH] Add initialization options for scaled ramps --- progress/progress.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/progress/progress.go b/progress/progress.go index 6e0e64b..e0da642 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -26,20 +26,30 @@ func WithDefaultRamp() Option { // WithRamp sets a gradient fill blending between two colors. func WithRamp(colorA, colorB string) Option { - a, _ := colorful.Hex(colorA) - b, _ := colorful.Hex(colorB) return func(m *Model) { - m.useRamp = true - m.rampColorA = a - m.rampColorB = b + m.setRamp(colorA, colorB, false) } } +// WithDefaultScaledRamp sets a gradient with default colors, and scales the +// gradient to fit the filled portion of the ramp. +func WithDefaultScaledRamp() Option { + return WithScaledRamp("#00dbde", "#fc00ff") +} + // WithScaledRamp scales the gradient to fit the width of the filled portion of // the progress bar. -func WithScaledRamp() Option { +func WithScaledRamp(colorA, colorB string) Option { return func(m *Model) { - m.scaleRamp = true + m.setRamp(colorA, colorB, true) + } +} + +// WithSoildFill sets the progress to use a solid fill with the given color. +func WithSolidFill(color string) Option { + return func(m *Model) { + m.FullColor = color + m.useRamp = false } } @@ -140,3 +150,12 @@ func (m Model) bar(percent float64, textWidth int) string { return b.String() } + +func (m *Model) setRamp(colorA, colorB string, scaled bool) { + a, _ := colorful.Hex(colorA) + b, _ := colorful.Hex(colorB) + m.useRamp = true + m.scaleRamp = scaled + m.rampColorA = a + m.rampColorB = b +}