First commit
This commit is contained in:
102
main.go
Normal file
102
main.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
// Brew represents our mock data structure
|
||||
type Brew struct {
|
||||
Name string
|
||||
Hops string
|
||||
Progress int
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
|
||||
// 1. Mock Data
|
||||
brews := []Brew{
|
||||
{"Midnight Stout", "Fuggles, Goldings", 75},
|
||||
{"Neon IPA", "Citra, Mosaic, Galaxy", 40},
|
||||
{"Summer Wheat", "Saaz, Hallertau", 95},
|
||||
{"Pacific Pale Ale", "Cascade, Amarillo", 10},
|
||||
}
|
||||
|
||||
// 2. Header with ASCII Logo (Top Right)
|
||||
// We use a TextView for the logo to allow right-alignment
|
||||
logo := tview.NewTextView().
|
||||
SetTextAlign(tview.AlignRight).
|
||||
SetDynamicColors(true).
|
||||
SetText(`[yellow]
|
||||
____ __ __ _
|
||||
| __ ) _ __ _____ __| \/ | __ _ ___| |_ ___ _ __
|
||||
| _ \| '__/ _ \ \ /\ / /| |\/| |/ _` + "`" + `/ __| __/ _ \ '__|
|
||||
| |_) | | | __/\ V V / | | | | (_| \__ \ || __/ |
|
||||
|____/|_| \___| \_/\_/ |_| |_|\__,_|___/\__\___|_|
|
||||
`)
|
||||
|
||||
title := tview.NewTextView().
|
||||
SetText(" BrewMaster v0.1.0 - Active Brews").
|
||||
SetTextColor(tcell.ColorCyan)
|
||||
|
||||
header := tview.NewFlex().
|
||||
AddItem(title, 0, 1, false).
|
||||
AddItem(logo, 0, 2, false)
|
||||
|
||||
// 3. Main Table (K9s Style)
|
||||
table := tview.NewTable().
|
||||
SetBorders(false).
|
||||
SetSelectable(true, false)
|
||||
|
||||
// Set Table Headers
|
||||
headers := []string{"NAME", "HOPS", "PROGRESS", "STATUS"}
|
||||
for c, h := range headers {
|
||||
table.SetCell(0, c, tview.NewTableCell(fmt.Sprintf("[yellow::b]%s", h)).
|
||||
SetSelectable(false))
|
||||
}
|
||||
|
||||
// Populate Mock Data
|
||||
for r, brew := range brews {
|
||||
row := r + 1
|
||||
table.SetCell(row, 0, tview.NewTableCell(brew.Name).SetTextColor(tcell.ColorWhite))
|
||||
table.SetCell(row, 1, tview.NewTableCell(brew.Hops).SetTextColor(tcell.ColorGray))
|
||||
|
||||
// Progress bar style
|
||||
progressStr := fmt.Sprintf("[%d%%] ", brew.Progress)
|
||||
table.SetCell(row, 2, tview.NewTableCell(progressStr).SetTextColor(tcell.ColorGreen))
|
||||
|
||||
status := "Fermenting"
|
||||
if brew.Progress > 90 {
|
||||
status = "Conditioning"
|
||||
}
|
||||
table.SetCell(row, 3, tview.NewTableCell(status).SetTextColor(tcell.ColorLightBlue))
|
||||
}
|
||||
|
||||
// 4. Footer (Help Menu)
|
||||
footer := tview.NewTextView().
|
||||
SetDynamicColors(true).
|
||||
SetText(" [black:gray] <Ctrl-C> Exit [white:black] [black:gray] <Enter> View Details [white:black] ")
|
||||
|
||||
// 5. Layout Assembly
|
||||
grid := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(header, 7, 0, false).
|
||||
AddItem(table, 0, 1, true).
|
||||
AddItem(footer, 1, 0, false)
|
||||
|
||||
// Global Keybindings
|
||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
if event.Key() == tcell.KeyCtrlC {
|
||||
app.Stop()
|
||||
os.Exit(0)
|
||||
}
|
||||
return event
|
||||
})
|
||||
|
||||
if err := app.SetRoot(grid, true).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user