-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.go
39 lines (31 loc) · 1.07 KB
/
mode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package shell
import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
)
// Mode is an interface which represents an input mode the shell can be in
// and is used to handle input
type Mode interface {
// Enter is called when the mode is entered
Enter(m Model) (Model, tea.Cmd)
// Leave is called when the mode is left, before the next mode is entered
Leave(m Model) (Model, tea.Cmd)
// Update is called when a message is received for the mode
Update(m Model, msg tea.Msg) (Model, tea.Cmd)
// AdditionalView is called to render additional output
// at the bottom of the screen
AdditionalView(m Model) string
// ShortHelp returns a list of key bindings and their descriptions
ShortHelp(m Model, keyMap KeyMap) []key.Binding
// FullHelp returns a list of key bindings and their descriptions
FullHelp(m Model, keyMap KeyMap) [][]key.Binding
}
// Enter tells the mode to enter the given mode leaving the old mode
func (m Model) Enter(mode Mode) tea.Cmd {
return func() tea.Msg {
return enterModeMsg{
ID: m.id,
Mode: mode,
}
}
}