Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: ux select prompt pgup & pgdown scrolling #149

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading