96 lines
2.4 KiB
Go
96 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
type Brew struct {
|
|
Name string
|
|
Status string
|
|
Progress string
|
|
}
|
|
|
|
func main() {
|
|
app := tview.NewApplication()
|
|
|
|
// Mock data for active brews
|
|
brews := []Brew{
|
|
{Name: "Belgian Tripel", Status: "Fermenting", Progress: "60%"},
|
|
{Name: "West Coast IPA", Status: "Boiling", Progress: "20%"},
|
|
{Name: "Imperial Stout", Status: "Conditioning", Progress: "90%"},
|
|
{Name: "Saison", Status: "Mashing", Progress: "10%"},
|
|
}
|
|
|
|
// Header
|
|
header := tview.NewTextView().
|
|
SetTextAlign(tview.AlignCenter).
|
|
SetText(" BrewMaster - Active Brews Dashboard ")
|
|
header.SetBorder(true).SetBorderColor(tcell.ColorYellow)
|
|
|
|
// Table for brews
|
|
table := tview.NewTable().
|
|
SetBorders(true).
|
|
SetSelectable(true, false)
|
|
|
|
// Set table headers
|
|
headers := []string{"Beer Name", "Status", "Progress"}
|
|
for i, h := range headers {
|
|
table.SetCell(0, i, tview.NewTableCell(h).SetTextColor(tcell.ColorYellow).SetSelectable(false))
|
|
}
|
|
|
|
// Populate table with mock data
|
|
for i, brew := range brews {
|
|
row := i + 1
|
|
table.SetCell(row, 0, tview.NewTableCell(brew.Name))
|
|
table.SetCell(row, 1, tview.NewTableCell(brew.Status))
|
|
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 : 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)
|
|
}
|
|
}
|