summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/slider/slider.go18
-rw-r--r--internal/switcher/switcher.go4
2 files changed, 19 insertions, 3 deletions
diff --git a/internal/slider/slider.go b/internal/slider/slider.go
index 884d141..bfbc069 100644
--- a/internal/slider/slider.go
+++ b/internal/slider/slider.go
@@ -35,11 +35,20 @@ func New(label byte, maxVal int, opts ...progress.Option) Model {
func (m Model) Title() string { return fmt.Sprintf("%c", m.label) }
func (m Model) Init() tea.Cmd {
- return m.progress.Init()
+ // Triggering a frame message Update here will force the progress bar to
+ // render immediately. This is necessary because progress bars only render
+ // when their state changes. Without this, there is a disrepancy between
+ // the initial state of the progress bar and the initial state of the slider.
+
+ // There's no sugar-coating it: This is a hack. But it works...
+ _, cmd := m.Update(progress.FrameMsg{})
+ return cmd
}
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+ cmds := []tea.Cmd{}
keys := newKeybinds()
+
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
@@ -54,12 +63,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
return m, m.progress.SetPercent(m.Pcnt())
case progress.FrameMsg:
+ if m.progress.Percent() != m.Pcnt() {
+ cmds = append(cmds, m.progress.SetPercent(m.Pcnt()))
+ }
progressModel, cmd := m.progress.Update(msg)
m.progress = progressModel.(progress.Model)
- return m, cmd
+ cmds = append(cmds, cmd)
default:
- return m, nil
}
+ return m, tea.Batch(cmds...)
}
func (m Model) ViewValue(current int) string {
diff --git a/internal/switcher/switcher.go b/internal/switcher/switcher.go
index eee92df..b534e54 100644
--- a/internal/switcher/switcher.go
+++ b/internal/switcher/switcher.go
@@ -2,6 +2,7 @@ package switcher
import (
"fmt"
+ "log/slog"
"github.com/ChausseBenjamin/termpicker/internal/colors"
"github.com/ChausseBenjamin/termpicker/internal/picker"
@@ -64,6 +65,7 @@ func (m Model) View() string {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
keys := newKeybinds()
cmds := []tea.Cmd{}
+ slog.Info("Received tea.Msg", "tea_msg", msg, "type", fmt.Sprintf("%T", msg))
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
@@ -102,6 +104,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
+ default:
+ // fmt.Printf("\nmsg: %T\n", msg)
}
for i, p := range m.pickers {
newActive, cmd := p.Update(msg)