tui: rename

This commit is contained in:
Matt Low 2024-09-30 04:32:47 +00:00
parent 2fed682969
commit ce7b07ad95

View File

@ -73,7 +73,7 @@ func NewWithGroups(groups []OptionGroup) Model {
} }
m.filterItems() m.filterItems()
m.content.SetContent(m.renderList()) m.content.SetContent(m.renderOptionsList())
return m return m
} }
@ -113,12 +113,10 @@ func (m *Model) filterItems() {
if len(m.filteredIndices) > 0 && prevSelection != nil { if len(m.filteredIndices) > 0 && prevSelection != nil {
// Preserve previous selection if possible // Preserve previous selection if possible
for i, filterIdx := range m.filteredIndices { for i, filterIdx := range m.filteredIndices {
if prevSelection.groupIndex == filterIdx.groupIndex { if prevSelection.groupIndex == filterIdx.groupIndex && prevSelection.optionIndex == filterIdx.optionIndex {
if prevSelection.optionIndex == filterIdx.optionIndex { m.selected = i
m.selected = i found = true
found = true break
break
}
} }
} }
} }
@ -165,7 +163,7 @@ func (m *Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return *m, func() tea.Msg { return *m, func() tea.Msg {
idx := m.filteredIndices[m.selected] idx := m.filteredIndices[m.selected]
return MsgOptionSelected{ return MsgOptionSelected{
ID: m.ID, ID: m.ID,
Option: m.optionGroups[idx.groupIndex].Options[idx.optionIndex], Option: m.optionGroups[idx.groupIndex].Options[idx.optionIndex],
} }
} }
@ -180,7 +178,7 @@ func (m *Model) Update(msg tea.Msg) (Model, tea.Cmd) {
} }
func (m *Model) refreshContent() { func (m *Model) refreshContent() {
m.content.SetContent(m.renderList()) m.content.SetContent(m.renderOptionsList())
m.ensureSelectedVisible() m.ensureSelectedVisible()
} }
@ -219,12 +217,12 @@ func (m *Model) View() string {
return lipgloss.JoinVertical(lipgloss.Left, parts...) return lipgloss.JoinVertical(lipgloss.Left, parts...)
} }
func (m *Model) renderList() string { func (m *Model) renderOptionsList() string {
var sb strings.Builder
yOffset := 0 yOffset := 0
lastGroupIndex := -1 lastGroupIndex := -1
m.itemYOffsets = make([]int, len(m.filteredIndices)) m.itemYOffsets = make([]int, len(m.filteredIndices))
var sb strings.Builder
for i, idx := range m.filteredIndices { for i, idx := range m.filteredIndices {
if idx.groupIndex != lastGroupIndex { if idx.groupIndex != lastGroupIndex {
group := m.optionGroups[idx.groupIndex].Name group := m.optionGroups[idx.groupIndex].Name
@ -258,6 +256,5 @@ func (m *Model) renderList() string {
sb.WriteRune('\n') sb.WriteRune('\n')
} }
} }
return sb.String() return sb.String()
} }