Refactor the keybinding stuff + add backspace

This commit is contained in:
Christian Rocha
2020-01-17 20:46:34 -05:00
parent 051a370769
commit 208f421470
4 changed files with 108 additions and 41 deletions

View File

@@ -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

View File

@@ -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
}