-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.go
89 lines (74 loc) · 1.64 KB
/
cmd.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package soda
import (
"time"
tea "github.com/charmbracelet/bubbletea"
)
// Back to the previous state
func Back() tea.Msg {
return _BackMsg{Steps: 1}
}
// BackN traverses the history N states back
func BackN(n int) tea.Cmd {
if n < 0 {
panic("n < 0")
}
return func() tea.Msg {
return _BackMsg{Steps: n}
}
}
// BackToRoot traverses to the first (initial) State in the history
func BackToRoot() tea.Msg {
return _BackToRootMsg{}
}
// PushState will push a new State
func PushState(state State) tea.Cmd {
return func() tea.Msg {
return _PushStateMsg{State: stateWrapper{
State: state,
SaveToHistory: true,
}}
}
}
// PushTempState will push a new State that won't be saved into history
func PushTempState(state State) tea.Cmd {
return func() tea.Msg {
return _PushStateMsg{State: stateWrapper{
State: state,
SaveToHistory: false,
}}
}
}
// Notify sends a notification with the default time.Duration
func Notify(message string) tea.Cmd {
return func() tea.Msg {
return _NotificationMsg{Message: message}
}
}
// NotifyWithDuration sends a notification with the given time.Duration ignoring the default
func NotifyWithDuration(message string, duration time.Duration) tea.Cmd {
return func() tea.Msg {
return _NotificationWithDurationMsg{
_NotificationMsg: _NotificationMsg{
Message: message,
},
Duration: duration,
}
}
}
func SendError(err error) tea.Cmd {
return func() tea.Msg {
return err
}
}
func Wrap(supplier func() tea.Cmd) tea.Cmd {
return func() tea.Msg {
cmd := supplier()
if cmd == nil {
return nil
}
return cmd()
}
}
func Redraw() tea.Msg {
return _RedrawMsg{}
}