60255
Zn
Zoea-Nova / files
Zoea-Nova / internal / tui / help.go
1.9 KB
1package tui 2 3import ( 4 "strings" 5 6 "github.com/charmbracelet/lipgloss" 7) 8 9type helpItem struct { 10 key string 11 desc string 12} 13 14var helpItems = []helpItem{ 15 {"q / Ctrl+C", "Quit"}, 16 {"n", "New mysis"}, 17 {"d", "Delete selected mysis"}, 18 {"r", "Relaunch selected mysis"}, 19 {"s", "Stop selected mysis"}, 20 {"b", "Broadcast message to all"}, 21 {"m", "Message selected mysis"}, 22 {"c", "Configure selected mysis"}, 23 {"Tab / Shift+Tab", "Navigate myses"}, 24 {"Enter", "Focus selected mysis"}, 25 {"Esc", "Back / Cancel"}, 26 {"↑ / ↓ / k / j", "Scroll / Browse history"}, 27 {"PgUp / PgDn", "Scroll page"}, 28 {"G / End", "Go to bottom"}, 29 {"?", "Toggle help"}, 30} 31 32// RenderHelp renders the help overlay. 33func RenderHelp(width, height int) string { 34 var lines []string 35 lines = append(lines, titleStyle.Render(" ⬥═══ ⬡ COMMAND REFERENCE ⬡ ═══⬥")) 36 lines = append(lines, "") 37 38 maxKeyLen := 0 39 for _, item := range helpItems { 40 keyWidth := lipgloss.Width(item.key) 41 if keyWidth > maxKeyLen { 42 maxKeyLen = keyWidth 43 } 44 } 45 46 for _, item := range helpItems { 47 key := helpKeyStyle.Render(padRight(item.key, maxKeyLen)) 48 desc := helpDescStyle.Render(item.desc) 49 lines = append(lines, key+" "+desc) 50 } 51 52 content := strings.Join(lines, "\n") 53 54 // Center the help box 55 box := helpStyle.Render(content) 56 57 // Calculate position to center 58 boxWidth := lipgloss.Width(box) 59 boxHeight := lipgloss.Height(box) 60 61 padLeft := (width - boxWidth) / 2 62 padTop := (height - boxHeight) / 2 63 64 if padLeft < 0 { 65 padLeft = 0 66 } 67 if padTop < 0 { 68 padTop = 0 69 } 70 71 // Create padding 72 leftPad := strings.Repeat(" ", padLeft) 73 topPad := strings.Repeat("\n", padTop) 74 75 // Add left padding to each line 76 boxLines := strings.Split(box, "\n") 77 for i, line := range boxLines { 78 boxLines[i] = leftPad + line 79 } 80 81 return topPad + strings.Join(boxLines, "\n") 82} 83 84func padRight(s string, length int) string { 85 width := lipgloss.Width(s) 86 if width >= length { 87 return s 88 } 89 return s + strings.Repeat(" ", length-width) 90}