From 0847aee30e7ea3a8b7ac480b194dbd0e2311dd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Mon, 2 Jan 2023 13:23:38 -0500 Subject: [PATCH] Implemented cmd package --- ui/cmd/cmd.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ui/cmd/cmd.go diff --git a/ui/cmd/cmd.go b/ui/cmd/cmd.go new file mode 100644 index 0000000..ea48da4 --- /dev/null +++ b/ui/cmd/cmd.go @@ -0,0 +1,57 @@ +package cmd + +import tea "github.com/charmbracelet/bubbletea" + +type CallType int8 + +const ( + WinOpen CallType = iota + WinFocus + WinBlur + + ViewFocus + ViewBlur + ViewRefreshData +) + +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 + } +} + +func (cmd *Command) GetArg(name string) interface{} { + if iface, ok := cmd.Args[name]; ok { + return iface + } + + return nil +}