-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode_command_running.go
60 lines (48 loc) · 1.2 KB
/
mode_command_running.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package shell
import (
"github.com/charmbracelet/bubbles/key"
tea "github.com/charmbracelet/bubbletea"
)
type CommandRunningMode struct{ KeepInputContent bool }
var _ Mode = (*CommandRunningMode)(nil)
func (c *CommandRunningMode) Enter(m Model) (Model, tea.Cmd) {
return m, nil
}
func (c *CommandRunningMode) Leave(m Model) (Model, tea.Cmd) {
return m, nil
}
func (c *CommandRunningMode) Update(m Model, msg tea.Msg) (Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.cfg.KeyMap.Cancel):
if m.currentCmdCancel != nil {
m.currentCmdCancel()
m.currentCmdCancel = nil
return m, nil
} else {
return m, m.Shutdown
}
}
}
return m, nil
}
func (c *CommandRunningMode) AdditionalView(m Model) string {
return ""
}
func (c *CommandRunningMode) ShortHelp(m Model, keyMap KeyMap) []key.Binding {
cancel := keyMap.Cancel
if m.currentCmdCancel != nil {
cancel.SetHelp(cancel.Help().Key, "stop executing command")
} else {
cancel.SetHelp(cancel.Help().Key, "quit")
}
return []key.Binding{
cancel,
}
}
func (c *CommandRunningMode) FullHelp(m Model, keyMap KeyMap) [][]key.Binding {
return [][]key.Binding{
c.ShortHelp(m, keyMap),
}
}