Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
add choice view
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 9, 2022
1 parent 610d95d commit 9471a9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions tui/node_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (v *NodeView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
if v.model.state == nodeViewState {
switch {
// FIXME enter duplicated on last item
case key.Matches(m, keys.Enter, keys.Up, keys.Down):
if key.Matches(m, keys.Enter, keys.Down) {
cmds = append(cmds, v.FocusNextWidget()...)
Expand Down
21 changes: 14 additions & 7 deletions tui/widget/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ func (v *BaseView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, cmd = v.Widgets[v.focus].Update(msg)
return v, cmd
}
default:
for i := 0; i < len(v.Widgets); i++ {
_, cmd = v.Widgets[v.focus].Update(msg)
cmds = append(cmds, cmd)
}
}
for i := 0; i < len(v.Widgets); i++ {
_, cmd = v.Widgets[v.focus].Update(msg)
cmds = append(cmds, cmd)
}

return v, tea.Batch(cmds...)
Expand All @@ -75,7 +74,7 @@ func (v *BaseView) View() string {
continue
}
str = lipgloss.JoinVertical(lipgloss.Left, str, v.Widgets[i].View())
log.Debug(fmt.Sprintf("cur h %d, view h %d", lipgloss.Height(str), v.height))
//log.Debug(fmt.Sprintf("cur h %d, view h %d", lipgloss.Height(str), v.height))
}
return str
}
Expand Down Expand Up @@ -106,10 +105,18 @@ func (v *BaseView) AddWidget(widget Widget) {
}

func (v *BaseView) FocusNextWidget() []tea.Cmd {
return v.setFocusWidget(v.idxAfterFocusWidget(), FocusFirstMode)
nextFocus := v.idxAfterFocusWidget()
if nextFocus == v.focus {
return nil
}
return v.setFocusWidget(nextFocus, FocusFirstMode)
}

func (v *BaseView) FocusPreWidget() []tea.Cmd {
nextFocus := v.idxBeforeFocusWidget()
if nextFocus == v.focus {
return nil
}
return v.setFocusWidget(v.idxBeforeFocusWidget(), FocusLastMode)
}

Expand Down

0 comments on commit 9471a9a

Please sign in to comment.