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 055acef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/uxBlock/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ 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":
switch msg.Type {

Check failure on line 70 in src/uxBlock/prompt.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux amd64

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyUp, tea.KeyDown, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyPgUp, tea.KeyPgDown, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)

Check failure on line 70 in src/uxBlock/prompt.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux 386

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyUp, tea.KeyDown, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyPgUp, tea.KeyPgDown, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)

Check failure on line 70 in src/uxBlock/prompt.go

View workflow job for this annotation

GitHub Actions / Build && tests for darwin amd64

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyUp, tea.KeyDown, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyPgUp, tea.KeyPgDown, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)
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
Expand All @@ -96,7 +97,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
24 changes: 19 additions & 5 deletions src/uxBlock/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,35 @@ func (m *selectModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !ok {
return m, nil
}
switch keyMsg.String() {
case "ctrl+c":

switch keyMsg.Type {

Check failure on line 100 in src/uxBlock/select.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux amd64

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyRight, tea.KeyLeft, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)

Check failure on line 100 in src/uxBlock/select.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux 386

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyRight, tea.KeyLeft, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)

Check failure on line 100 in src/uxBlock/select.go

View workflow job for this annotation

GitHub Actions / Build && tests for darwin amd64

missing cases in switch of type tea.KeyType: tea.KeyNull|tea.KeyCtrlAt, tea.KeyBackspace|tea.KeyCtrlQuestionMark, tea.KeyTab|tea.KeyCtrlI, tea.KeyEsc|tea.KeyEscape|tea.KeyCtrlOpenBracket, tea.KeyCtrlA, tea.KeyCtrlB, tea.KeyCtrlD, tea.KeyCtrlE, tea.KeyCtrlF, tea.KeyCtrlG, tea.KeyCtrlH, tea.KeyCtrlJ, tea.KeyCtrlK, tea.KeyCtrlL, tea.KeyCtrlN, tea.KeyCtrlO, tea.KeyCtrlP, tea.KeyCtrlQ, tea.KeyCtrlR, tea.KeyCtrlS, tea.KeyCtrlT, tea.KeyCtrlU, tea.KeyCtrlV, tea.KeyCtrlW, tea.KeyCtrlX, tea.KeyCtrlY, tea.KeyCtrlZ, tea.KeyCtrlBackslash, tea.KeyCtrlCloseBracket, tea.KeyCtrlCaret, tea.KeyCtrlUnderscore, tea.KeyRunes, tea.KeyRight, tea.KeyLeft, tea.KeyShiftTab, tea.KeyHome, tea.KeyEnd, tea.KeyCtrlPgUp, tea.KeyCtrlPgDown, tea.KeyDelete, tea.KeyInsert, tea.KeySpace, tea.KeyCtrlUp, tea.KeyCtrlDown, tea.KeyCtrlRight, tea.KeyCtrlLeft, tea.KeyCtrlHome, tea.KeyCtrlEnd, tea.KeyShiftUp, tea.KeyShiftDown, tea.KeyShiftRight, tea.KeyShiftLeft, tea.KeyShiftHome, tea.KeyShiftEnd, tea.KeyCtrlShiftUp, tea.KeyCtrlShiftDown, tea.KeyCtrlShiftLeft, tea.KeyCtrlShiftRight, tea.KeyCtrlShiftHome, tea.KeyCtrlShiftEnd, tea.KeyF1, tea.KeyF2, tea.KeyF3, tea.KeyF4, tea.KeyF5, tea.KeyF6, tea.KeyF7, tea.KeyF8, tea.KeyF9, tea.KeyF10, tea.KeyF11, tea.KeyF12, tea.KeyF13, tea.KeyF14, tea.KeyF15, tea.KeyF16, tea.KeyF17, tea.KeyF18, tea.KeyF19, tea.KeyF20 (exhaustive)
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 055acef

Please sign in to comment.