From 68d82a3f866e2310f487960fbfc2c9e23cdd4698 Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Sat, 14 May 2022 19:44:37 -0400 Subject: [PATCH] Refactor: change command string to command struct --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 3e5bdf1..b099f02 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ const ( type sessionOrCommand struct { displayString string - commandString string + command *exec.Cmd } type Choices [][]sessionOrCommand @@ -61,7 +61,7 @@ func getBrowserSessions() []sessionOrCommand { for _, entry := range fileList { if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".yml") { log.Printf("INFO %s", entry.Name()) - result = append(result, sessionOrCommand{displayString: strings.TrimSuffix(entry.Name(), ".yml"), commandString: ""}) + result = append(result, sessionOrCommand{displayString: strings.TrimSuffix(entry.Name(), ".yml"), command: nil}) } } // log.Printf("result: %v", result) @@ -78,10 +78,10 @@ func initialModel() model { getBrowserSessions(), []sessionOrCommand{{ displayString: "newsboat", - commandString: "newsboat", + command: exec.Command("xterm", "-maximized", "-e", "newsboat"), }, { displayString: "bottom", - commandString: "btm --group --battery --color gruvbox-light", + command: exec.Command("xterm", "-maximized", "-e", "btm", "--group", "--battery", "--color", "gruvbox-light"), }}, }, // An array of maps which indicates which choices are selected. @@ -94,8 +94,8 @@ func initialModel() model { func launch(m model) tea.Cmd { return func() tea.Msg { var result statusMsg - for j, item := range m.choices[0] { - if _, ok := m.selected[0][j]; ok { + for j, item := range m.choices[BrowserSessions] { + if _, ok := m.selected[BrowserSessions][j]; ok { cmd := exec.Command("qutebrowser", "--restore", item.displayString) err := cmd.Start() result += statusMsg(fmt.Sprintf("Launching Qutebrowser session: %v\n", item.displayString)) @@ -106,9 +106,9 @@ func launch(m model) tea.Cmd { } } - for k, item := range m.choices[1] { - if _, ok := m.selected[1][k]; ok { - cmd := exec.Command("xterm", "-e", item.commandString) + for k, item := range m.choices[Commands] { + if _, ok := m.selected[Commands][k]; ok { + cmd := item.command err := cmd.Start() result += statusMsg(fmt.Sprintf("Launching command: %v\n", item.displayString)) if err != nil {