mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-01-11 22:41:03 +03:00
Add ability to style percentage readout
This commit is contained in:
parent
79ca4d09d1
commit
7e5ef42924
@ -91,6 +91,7 @@ type Model struct {
|
|||||||
// Settings for rendering the numeric percentage
|
// Settings for rendering the numeric percentage
|
||||||
ShowPercentage bool
|
ShowPercentage bool
|
||||||
PercentFormat string // a fmt string for a float
|
PercentFormat string // a fmt string for a float
|
||||||
|
PercentageStyle *termenv.Style
|
||||||
|
|
||||||
useRamp bool
|
useRamp bool
|
||||||
rampColorA colorful.Color
|
rampColorA colorful.Color
|
||||||
@ -127,9 +128,12 @@ func NewModel(opts ...Option) (*Model, error) {
|
|||||||
func (m Model) View(percent float64) string {
|
func (m Model) View(percent float64) string {
|
||||||
b := strings.Builder{}
|
b := strings.Builder{}
|
||||||
if m.ShowPercentage {
|
if m.ShowPercentage {
|
||||||
s := fmt.Sprintf(m.PercentFormat, percent*100)
|
percentage := fmt.Sprintf(m.PercentFormat, percent*100)
|
||||||
m.bar(&b, percent, ansi.PrintableRuneWidth(s))
|
if m.PercentageStyle != nil {
|
||||||
b.WriteString(s)
|
percentage = m.PercentageStyle.Styled(percentage)
|
||||||
|
}
|
||||||
|
m.bar(&b, percent, ansi.PrintableRuneWidth(percentage))
|
||||||
|
b.WriteString(percentage)
|
||||||
} else {
|
} else {
|
||||||
m.bar(&b, percent, 0)
|
m.bar(&b, percent, 0)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user