diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-12-27 18:44:20 -0500 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-12-27 18:44:20 -0500 |
commit | 914633df3e8da138bc2ac78f69fe340832e2283d (patch) | |
tree | 148d0f8da77686ff7d713d8a233b3545b7994e2a /internal/picker | |
parent | 98a0bf6a3144a7a614a9c9cdb0a077c2ed2d252f (diff) |
fix: refactor picker View()
Diffstat (limited to 'internal/picker')
-rw-r--r-- | internal/picker/picker.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/picker/picker.go b/internal/picker/picker.go index 3094396..1c39aaa 100644 --- a/internal/picker/picker.go +++ b/internal/picker/picker.go @@ -2,6 +2,7 @@ package picker import ( "fmt" + "strings" "github.com/ChausseBenjamin/termpicker/internal/colors" "github.com/ChausseBenjamin/termpicker/internal/slider" @@ -108,25 +109,24 @@ func (m Model) Init() tea.Cmd { return tea.Batch(cmds...) } -func (m Model) View() string { - var s string +func ViewSlider(active bool, s slider.Model) string { + if active { + return fmt.Sprintf("%s %s", + ui.Style().PickerCursor.Render(ui.PickerSelRune), + s.View(), + ) + } + return fmt.Sprintf(" %s", + s.View(), + ) +} - newline := "" +func (m Model) View() string { + sliderList := make([]string, len(m.sliders)) for i, slider := range m.sliders { - if i > 0 { - newline = "\n" - } - if i == m.active { - s += fmt.Sprintf("%v%s %s", - newline, - ui.Style().PickerCursor.Render(ui.PickerSelRune), - slider.View(), - ) - } else { - s += fmt.Sprintf("%v %s", newline, slider.View()) - } + sliderList[i] = ViewSlider(i == m.active, slider) } - return s + return strings.Join(sliderList, "\n") } func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |