From 0ce268de3542b9d71fe92d411424b6e2ed0ea0d5 Mon Sep 17 00:00:00 2001 From: Eli Winderickx Date: Mon, 13 Apr 2026 21:13:43 +0200 Subject: [PATCH] feat: add command menu triggered by : with quit command Co-authored-by: aider (ollama_chat/gemma4:31b) --- main.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c696168..702d490 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "github.com/rivo/tview" "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" ) type Brew struct { @@ -49,18 +49,46 @@ func main() { table.SetCell(row, 2, tview.NewTableCell(brew.Progress)) } + // Command Input Field + cmdInput := tview.NewInputField(). + SetLabel(": "). + SetFieldWidth(0) + + // Handle command execution + cmdInput.SetDoneFunc(func(key tcell.EventKey) { + text := cmdInput.GetText() + if text == "q" || text == "quit" { + app.Stop() + } else { + // Reset input and return focus to table if command is unknown + cmdInput.SetText("") + app.SetFocus(table) + } + }) + // Footer footer := tview.NewTextView(). SetTextAlign(tview.AlignCenter). - SetText(" Press Ctrl+C to exit ") + SetText(" Press : for commands | Press Ctrl+C to exit ") // Layout: Vertical flex flex := tview.NewFlex(). SetDirection(tview.FlexRow). AddItem(header, 1, 1, false). AddItem(table, 0, 1, true). + AddItem(cmdInput, 1, 1, false). AddItem(footer, 1, 1, false) + // Global input capture to trigger the command menu + app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { + if event.Key() == tcell.KeyRune && event.Rune() == ':' { + app.SetFocus(cmdInput) + cmdInput.SetText("") + return nil // Consume the event so ':' isn't typed into the field + } + return event + }) + if err := app.SetRoot(flex, true).Run(); err != nil { fmt.Printf("Error running application: %v\n", err) }