mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-01-11 14:38:10 +03:00
Reduce progress component to (more or less) a pure view function
We really only need the View function in this case since the progress value will come from the program that implements this.
This commit is contained in:
parent
68e87e08c5
commit
3dea7d036e
@ -3,14 +3,10 @@ package progress
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/lucasb-eyer/go-colorful"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
// Value is explicit type of, you know, progression. Can be 0.0 < x < 1.0.
|
||||
type Value float64
|
||||
|
||||
type Model struct {
|
||||
// Left side color of progress bar. By default, it's #00dbde
|
||||
StartColor colorful.Color
|
||||
@ -21,10 +17,6 @@ type Model struct {
|
||||
// Width of progress bar in symbols.
|
||||
Width int
|
||||
|
||||
// Which part of bar need to visualise. Can be 0.0 < Progress < 1.0, if value is bigger or smaller, it'll
|
||||
// be mapped to this values
|
||||
Progress float64
|
||||
|
||||
// filament rune of done part of progress bar. it's █ by default
|
||||
FilamentSymbol rune
|
||||
|
||||
@ -49,28 +41,8 @@ func NewModel(size int) *Model {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch cmd := msg.(type) {
|
||||
case Value:
|
||||
if cmd > 1 {
|
||||
cmd = 1
|
||||
}
|
||||
if cmd < 0 {
|
||||
cmd = 0
|
||||
}
|
||||
|
||||
m.Progress = float64(cmd)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m *Model) View() string {
|
||||
ramp := make([]string, int(float64(m.Width)*m.Progress))
|
||||
func (m *Model) View(percent float64) string {
|
||||
ramp := make([]string, int(float64(m.Width)*percent))
|
||||
for i := 0; i < len(ramp); i++ {
|
||||
gradientPart := float64(m.Width)
|
||||
if m.FullGradientMode {
|
||||
|
Loading…
Reference in New Issue
Block a user