Skip to content

Commit

Permalink
improvement: ux select prompt pgup & pgdown scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
l-hellmann committed May 9, 2024
1 parent 11b9587 commit 17a8fa7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/uxBlock/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,27 @@ func (m *promptModel) Init() tea.Cmd {

func (m *promptModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.KeyMsg); ok {
switch msg.String() {
case "ctrl+c":
//nolint:exhaustive
switch msg.Type {
case tea.KeyCtrlC:
m.canceled = true
return m, tea.Quit

case "left":
case tea.KeyLeft:
if m.cursor > 0 {
m.cursor--
}

case "right":
case tea.KeyRight:
if m.cursor < len(m.choices)-1 {
m.cursor++
}
case "enter":

case tea.KeyEnter:
m.quiting = true

return m, tea.Quit
default:
}
}

Expand All @@ -96,7 +99,7 @@ func (m *promptModel) View() string {
return ""
}

buttonsTexts := []string{}
var buttonsTexts []string
for i, choice := range m.choices {
if i == m.cursor {
buttonsTexts = append(buttonsTexts, styles.ActiveDialogButton().Render(choice))
Expand Down
25 changes: 20 additions & 5 deletions src/uxBlock/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,36 @@ func (m *selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !ok {
return m, nil
}
switch keyMsg.String() {
case "ctrl+c":

//nolint:exhaustive
switch keyMsg.Type {
case tea.KeyCtrlC:
m.canceled = true
return m, tea.Quit

case "up":
case tea.KeyUp:
if m.cursor > 0 {
m.cursor--
}

case "down":
case tea.KeyDown:
if m.cursor < len(m.tableBody.rows)-1 {
m.cursor++
}
case "enter":

case tea.KeyPgUp:
m.cursor -= 5
if m.cursor < 0 {
m.cursor = 0
}

case tea.KeyPgDown:
m.cursor += 5
if lastItemIndex := len(m.tableBody.rows) - 1; m.cursor > lastItemIndex {
m.cursor = lastItemIndex
}

case tea.KeyEnter:
m.quiting = true

if !m.cfg.multiSelect {
Expand Down
2 changes: 1 addition & 1 deletion src/uxBlock/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (m *spinnerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit

case tea.KeyMsg:
if msg.String() == "ctrl+c" {
if msg.Type == tea.KeyCtrlC {
m.canceled = true
m.quiting = true
return m, tea.Quit
Expand Down

0 comments on commit 17a8fa7

Please sign in to comment.