From 98e569d9be4c4d8508ede936c1e5962479f6ec30 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 12 Jan 2026 22:09:44 +0000 Subject: [PATCH] a bit of a clean up --- repl/commands.go | 89 ------------------------------------------------ repl/repl.go | 62 --------------------------------- 2 files changed, 151 deletions(-) delete mode 100644 repl/commands.go delete mode 100644 repl/repl.go diff --git a/repl/commands.go b/repl/commands.go deleted file mode 100644 index 0a4c41d..0000000 --- a/repl/commands.go +++ /dev/null @@ -1,89 +0,0 @@ -package repl - -import ( - "fmt" - "strconv" -) - -type Command struct { - Name string - Usage string - ArgCheck func(args []string) error - Action func(args []string) error -} - -var ( - discoverDevicesREPLCmd = repl.Command{ - Name: "discover", - Usage: "discovers connected devices", - Action: func(r *repl.REPL, args []string) error { - err := perClerk.FindDevices() - if err != nil { - return err - } - - return nil - }, - } - - listDevicesREPLCmd = repl.Command{ - Name: "list", - Usage: "lists connected devices", - Action: func(r *repl.REPL, args []string) error { - _ = perClerk.ListDevices() - - return nil - }, - } - - listDeviceAPIREPLCmd = repl.Command{ - Name: "v-api", - Usage: "shows API of a device - pass its ID", - Action: func(r *repl.REPL, args []string) error { - // We should add this to the REPL instead - if len(args) < 1 { - return fmt.Errorf("requires at least on argument") - } - - // First and only argument should be the ID of the device we want to use - targetID, err := strconv.ParseInt(args[0], 10, 0) - if err != nil { - return err - } - - err = perClerk.ListDeviceAPI(uint8(targetID)) - if err != nil { - fmt.Println("failed to view device API: ", err.Error()) - } - - return nil - }, - } - - runDeviceAPIREPLCmd = repl.Command{ - Name: "v-run", - Usage: "runs a funcion of a device - pass its ID and function name", - Action: func(r *repl.REPL, args []string) error { - // We should add this to the REPL instead - if len(args) < 3 { - return fmt.Errorf("requires at least on argument") - } - - // First and only argument should be the ID of the device we want to use - targetID, err := strconv.ParseInt(args[0], 10, 0) - if err != nil { - return err - } - - fnName := args[1] - fnArgs := args[2:] - - err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs) - if err != nil { - return err - } - - return nil - }, - } -) diff --git a/repl/repl.go b/repl/repl.go deleted file mode 100644 index 3f85878..0000000 --- a/repl/repl.go +++ /dev/null @@ -1,62 +0,0 @@ -package repl - -import ( - esdi "esdi/esdi" - - tea "github.com/charmbracelet/bubbletea" -) - -type model struct { - esdi *esdi.ESDI - mov string -} - -func initialMode() model { - return model{ - esdi: esdi.NewESDI(), - } -} - -func (m model) Init() tea.Cmd { - return nil -} - -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.String() { - case "ctrl+c", "q": - return m, tea.Quit - case "left", "h": - // Go left - m.mov = msg.String() - case "down", "j": - // Go down - m.mov = msg.String() - case "up", "k": - // Go up - m.mov = msg.String() - case "right", "l": - // Go right - m.mov = msg.String() - } - } - - return m, nil -} - -func (m model) View() string { - s := "What should we buy at the market?\n\n" - s += m.mov + "\n" - - return s -} - -func Run() error { - p := tea.NewProgram(initialMode()) - if _, err := p.Run(); err != nil { - return err - } - - return nil -}