1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00
neonmodem/ui/cmd/cmd.go

81 lines
1.1 KiB
Go
Raw Normal View History

2023-01-02 13:23:38 -05:00
package cmd
import tea "github.com/charmbracelet/bubbletea"
type CallType int8
const (
WinOpen CallType = iota
2023-01-02 16:45:42 -05:00
WinClose
2023-01-02 13:23:38 -05:00
WinFocus
WinBlur
2023-01-02 14:24:07 -05:00
WinRefreshData
2023-01-02 15:29:29 -05:00
WinFreshData
2023-01-02 13:23:38 -05:00
2023-01-06 19:41:28 -05:00
ViewOpen
2023-01-02 13:23:38 -05:00
ViewFocus
ViewBlur
ViewRefreshData
2023-01-02 15:29:29 -05:00
ViewFreshData
2023-01-02 16:45:42 -05:00
MsgError
2023-01-02 20:34:39 -05:00
WMCloseWin
2023-01-02 13:23:38 -05:00
)
type Arg struct {
Name string
Value interface{}
}
type Command struct {
Call CallType
Target string
Args map[string]interface{}
}
func New(
call CallType,
target string,
args ...Arg,
) *Command {
cmd := new(Command)
cmd.Call = call
cmd.Target = target
cmd.Args = make(map[string]interface{})
for _, arg := range args {
cmd.Args[arg.Name] = arg.Value
}
return cmd
}
func (cmd *Command) Tea() tea.Cmd {
return func() tea.Msg {
return *cmd
}
}
2023-01-02 19:45:49 -05:00
func (cmd *Command) AddArg(name string, value interface{}) {
cmd.Args[name] = value
}
2023-01-02 13:23:38 -05:00
func (cmd *Command) GetArg(name string) interface{} {
if iface, ok := cmd.Args[name]; ok {
return iface
}
return nil
}
2023-01-02 14:24:07 -05:00
func (cmd *Command) GetArgs() []Arg {
var args []Arg
for name, value := range cmd.Args {
args = append(args, Arg{Name: name, Value: value})
}
return args
}