mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
Refactor the keybinding stuff + add backspace
This commit is contained in:
@@ -22,14 +22,14 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
func update(message tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := mdl.(model)
|
||||
|
||||
switch message := msg.(type) {
|
||||
switch msg := message.(type) {
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
switch message {
|
||||
case "ctrl+c":
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "break":
|
||||
fallthrough
|
||||
case "esc":
|
||||
fallthrough
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
// TODO: This code feels messy. Clean it up.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -62,8 +64,8 @@ func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
func updateChoices(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
switch msg {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "j":
|
||||
fallthrough
|
||||
case "down":
|
||||
@@ -85,7 +87,7 @@ func updateChoices(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
fallthrough
|
||||
case "esc":
|
||||
fallthrough
|
||||
case "ctrl+c":
|
||||
case "break":
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
@@ -102,13 +104,13 @@ func updateChoices(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
func updateChosen(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case tea.KeyPressMsg:
|
||||
switch msg {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q":
|
||||
fallthrough
|
||||
case "esc":
|
||||
fallthrough
|
||||
case "ctrl+c":
|
||||
case "break":
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user