feat: add command menu triggered by : with quit command

Co-authored-by: aider (ollama_chat/gemma4:31b) <aider@aider.chat>
This commit is contained in:
2026-04-13 21:13:43 +02:00
parent 9d3b34dbd0
commit 0ce268de35

32
main.go
View File

@@ -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)
}