- Replace 12-item flat menu with 4-item main menu: Health Check, Export support bundle, Settings, Exit - Add Health Check screen (Lenovo-style): per-component checkboxes (GPU/MEM/DISK/CPU), Quick/Standard/Express modes, Run All, letter hotkeys G/M/S/C/R/A/1/2/3 - Add two-column main screen: left = menu, right = hardware panel with colored PASS/FAIL/CANCEL/N/A status per component; Tab/→ switches focus, Enter opens component detail - Add app.LoadHardwarePanel() + ComponentDetailResult() reading audit JSON and SAT summary.txt files - Move Network/Services/audit actions into Settings submenu - Export: support bundle only (remove separate audit JSON export) - Delete screen_acceptance.go; add screen_health_check.go, screen_settings.go, app/panel.go - Add BMC + CPU stress-ng tests to backlog - Update bible submodule - Rewrite tui_test.go for new screen/action structure Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
225 lines
5.9 KiB
Go
225 lines
5.9 KiB
Go
package tui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"bee/audit/internal/platform"
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
// Column widths for two-column main layout.
|
|
const leftColWidth = 30
|
|
|
|
var (
|
|
stylePass = lipgloss.NewStyle().Foreground(lipgloss.Color("10")) // bright green
|
|
styleFail = lipgloss.NewStyle().Foreground(lipgloss.Color("9")) // bright red
|
|
styleCancel = lipgloss.NewStyle().Foreground(lipgloss.Color("11")) // bright yellow
|
|
styleNA = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) // dark gray
|
|
)
|
|
|
|
func colorStatus(status string) string {
|
|
switch status {
|
|
case "PASS":
|
|
return stylePass.Render("PASS")
|
|
case "FAIL":
|
|
return styleFail.Render("FAIL")
|
|
case "CANCEL":
|
|
return styleCancel.Render("CANC")
|
|
default:
|
|
return styleNA.Render("N/A ")
|
|
}
|
|
}
|
|
|
|
func (m model) View() string {
|
|
if m.busy {
|
|
title := "bee"
|
|
if m.busyTitle != "" {
|
|
title = m.busyTitle
|
|
}
|
|
return fmt.Sprintf("%s\n\nWorking...\n\n[ctrl+c] quit\n", title)
|
|
}
|
|
switch m.screen {
|
|
case screenMain:
|
|
return renderTwoColumnMain(m)
|
|
case screenHealthCheck:
|
|
return renderHealthCheck(m)
|
|
case screenSettings:
|
|
return renderMenu("Settings", "Select action", m.settingsMenu, m.cursor)
|
|
case screenNetwork:
|
|
return renderMenu("Network", "Select action", m.networkMenu, m.cursor)
|
|
case screenServices:
|
|
return renderMenu("Services", "Select service", m.services, m.cursor)
|
|
case screenServiceAction:
|
|
return renderMenu("Service: "+m.selectedService, "Select action", m.serviceMenu, m.cursor)
|
|
case screenExportTargets:
|
|
return renderMenu("Export support bundle", "Select removable filesystem", renderTargetItems(m.targets), m.cursor)
|
|
case screenInterfacePick:
|
|
return renderMenu("Interfaces", "Select interface", renderInterfaceItems(m.interfaces), m.cursor)
|
|
case screenStaticForm:
|
|
return renderForm("Static IPv4: "+m.selectedIface, m.formFields, m.formIndex)
|
|
case screenConfirm:
|
|
title, body := m.confirmBody()
|
|
return renderConfirm(title, body, m.cursor)
|
|
case screenNvidiaSATSetup:
|
|
return renderNvidiaSATSetup(m)
|
|
case screenNvidiaSATRunning:
|
|
return renderNvidiaSATRunning()
|
|
case screenOutput:
|
|
return fmt.Sprintf("%s\n\n%s\n\n[enter/esc] back [ctrl+c] quit\n", m.title, strings.TrimSpace(m.body))
|
|
default:
|
|
return "bee\n"
|
|
}
|
|
}
|
|
|
|
// renderTwoColumnMain renders the main screen with menu on the left and hardware panel on the right.
|
|
func renderTwoColumnMain(m model) string {
|
|
// Left column lines
|
|
leftLines := []string{"bee", ""}
|
|
for i, item := range m.mainMenu {
|
|
pfx := " "
|
|
if !m.panelFocus && m.cursor == i {
|
|
pfx = "> "
|
|
}
|
|
leftLines = append(leftLines, pfx+item)
|
|
}
|
|
|
|
// Right column lines
|
|
rightLines := buildPanelLines(m)
|
|
|
|
// Render side by side
|
|
var b strings.Builder
|
|
maxRows := max(len(leftLines), len(rightLines))
|
|
for i := 0; i < maxRows; i++ {
|
|
l := ""
|
|
if i < len(leftLines) {
|
|
l = leftLines[i]
|
|
}
|
|
r := ""
|
|
if i < len(rightLines) {
|
|
r = rightLines[i]
|
|
}
|
|
w := lipgloss.Width(l)
|
|
if w < leftColWidth {
|
|
l += strings.Repeat(" ", leftColWidth-w)
|
|
}
|
|
b.WriteString(l + " │ " + r + "\n")
|
|
}
|
|
|
|
sep := strings.Repeat("─", leftColWidth) + "─┴─" + strings.Repeat("─", 46)
|
|
b.WriteString(sep + "\n")
|
|
|
|
if m.panelFocus {
|
|
b.WriteString("[↑↓] move [enter] details [tab/←] menu [ctrl+c] quit\n")
|
|
} else {
|
|
b.WriteString("[↑↓] move [enter] select [tab/→] panel [ctrl+c] quit\n")
|
|
}
|
|
|
|
return b.String()
|
|
}
|
|
|
|
func buildPanelLines(m model) []string {
|
|
p := m.panel
|
|
var lines []string
|
|
|
|
for _, h := range p.Header {
|
|
lines = append(lines, h)
|
|
}
|
|
if len(p.Header) > 0 && len(p.Rows) > 0 {
|
|
lines = append(lines, "")
|
|
}
|
|
|
|
for i, row := range p.Rows {
|
|
pfx := " "
|
|
if m.panelFocus && m.panelCursor == i {
|
|
pfx = "> "
|
|
}
|
|
status := colorStatus(row.Status)
|
|
lines = append(lines, fmt.Sprintf("%s%s %-4s %s", pfx, status, row.Key, row.Detail))
|
|
}
|
|
|
|
return lines
|
|
}
|
|
|
|
func renderTargetItems(targets []platform.RemovableTarget) []string {
|
|
items := make([]string, 0, len(targets))
|
|
for _, target := range targets {
|
|
desc := fmt.Sprintf("%s [%s %s]", target.Device, target.FSType, target.Size)
|
|
if target.Label != "" {
|
|
desc += " label=" + target.Label
|
|
}
|
|
if target.Mountpoint != "" {
|
|
desc += " mounted=" + target.Mountpoint
|
|
}
|
|
items = append(items, desc)
|
|
}
|
|
return items
|
|
}
|
|
|
|
func renderInterfaceItems(interfaces []platform.InterfaceInfo) []string {
|
|
items := make([]string, 0, len(interfaces))
|
|
for _, iface := range interfaces {
|
|
label := iface.Name
|
|
if len(iface.IPv4) > 0 {
|
|
label += " [" + strings.Join(iface.IPv4, ", ") + "]"
|
|
}
|
|
items = append(items, label)
|
|
}
|
|
return items
|
|
}
|
|
|
|
func renderMenu(title, subtitle string, items []string, cursor int) string {
|
|
var body strings.Builder
|
|
fmt.Fprintf(&body, "%s\n\n%s\n\n", title, subtitle)
|
|
if len(items) == 0 {
|
|
body.WriteString("(no items)\n")
|
|
} else {
|
|
for i, item := range items {
|
|
prefix := " "
|
|
if i == cursor {
|
|
prefix = "> "
|
|
}
|
|
fmt.Fprintf(&body, "%s%s\n", prefix, item)
|
|
}
|
|
}
|
|
body.WriteString("\n[↑/↓] move [enter] select [esc] back [ctrl+c] quit\n")
|
|
return body.String()
|
|
}
|
|
|
|
func renderForm(title string, fields []formField, idx int) string {
|
|
var body strings.Builder
|
|
fmt.Fprintf(&body, "%s\n\n", title)
|
|
for i, field := range fields {
|
|
prefix := " "
|
|
if i == idx {
|
|
prefix = "> "
|
|
}
|
|
fmt.Fprintf(&body, "%s%s: %s\n", prefix, field.Label, field.Value)
|
|
}
|
|
body.WriteString("\n[tab/↑/↓] move [enter] next/submit [backspace] delete [esc] cancel\n")
|
|
return body.String()
|
|
}
|
|
|
|
func renderConfirm(title, body string, cursor int) string {
|
|
options := []string{"Confirm", "Cancel"}
|
|
var out strings.Builder
|
|
fmt.Fprintf(&out, "%s\n\n%s\n\n", title, body)
|
|
for i, option := range options {
|
|
prefix := " "
|
|
if i == cursor {
|
|
prefix = "> "
|
|
}
|
|
fmt.Fprintf(&out, "%s%s\n", prefix, option)
|
|
}
|
|
out.WriteString("\n[←/→/↑/↓] move [enter] select [esc] cancel\n")
|
|
return out.String()
|
|
}
|
|
|
|
func resultCmd(title, body string, err error, back screen) tea.Cmd {
|
|
return func() tea.Msg {
|
|
return resultMsg{title: title, body: body, err: err, back: back}
|
|
}
|
|
}
|