chore(progress): use getters/setters for width

This commit is contained in:
Christian Rocha
2024-10-23 17:36:52 -04:00
parent d514f3d2bf
commit 39fb58b530
+14 -4
View File
@@ -92,7 +92,7 @@ func WithoutPercentage() Option {
// waiting for a tea.WindowSizeMsg.
func WithWidth(w int) Option {
return func(m *Model) {
m.Width = w
m.width = w
}
}
@@ -131,7 +131,7 @@ type Model struct {
tag int
// Total width of the progress bar, including percentage, if set.
Width int
width int
// "Filled" sections of the progress bar.
Full rune
@@ -171,7 +171,7 @@ type Model struct {
func New(opts ...Option) Model {
m := Model{
id: nextID(),
Width: defaultWidth,
width: defaultWidth,
Full: '█',
FullColor: "#7571F9",
Empty: '░',
@@ -221,6 +221,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
// Width returns the set width of the progress bar.
func (m Model) Width() int {
return m.width
}
// SetWidth sets the width of the progress bar.
func (m *Model) SetWidth(w int) {
m.width = w
}
// SetSpringOptions sets the frequency and damping for the current spring.
// Frequency corresponds to speed, and damping to bounciness. For details see:
//
@@ -286,7 +296,7 @@ func (m *Model) nextFrame() tea.Cmd {
func (m Model) barView(b *strings.Builder, percent float64, textWidth int) {
var (
tw = max(0, m.Width-textWidth) // total width
tw = max(0, m.width-textWidth) // total width
fw = int(math.Round((float64(tw) * percent))) // filled width
p float64
)