57 lines
1006 B
Go
57 lines
1006 B
Go
package main
|
|
|
|
import tea "github.com/charmbracelet/bubbletea"
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.WindowSizeMsg:
|
|
m.win_h = msg.Height
|
|
m.win_w = msg.Width
|
|
|
|
case tea.KeyMsg:
|
|
switch m.mode {
|
|
case NormalMode:
|
|
return m, m.input.Handle(&m, msg.String())
|
|
|
|
// TODO: This should be handled elsewhere
|
|
case InsertMode:
|
|
key := msg.String()
|
|
|
|
switch key {
|
|
case "esc":
|
|
if m.insertCount > 1 {
|
|
m.replayInsert()
|
|
}
|
|
|
|
// Allow i to step back, but a to stay put
|
|
if m.cursor.x > 0 {
|
|
m.cursor.x--
|
|
}
|
|
m.mode = NormalMode
|
|
m.insertCount = 0
|
|
m.insertKeys = nil
|
|
|
|
case "ctrl+c", "ctrl+d":
|
|
return m, tea.Quit
|
|
|
|
default:
|
|
// Record and process
|
|
m.insertKeys = append(m.insertKeys, key)
|
|
m.processInsertKey(key)
|
|
}
|
|
case CommandMode:
|
|
switch msg.String() {
|
|
case "esc":
|
|
m.mode = NormalMode
|
|
m.command = ""
|
|
|
|
default:
|
|
m.command += msg.String()
|
|
}
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|