@@ -3,7 +3,6 @@ package ui
33import (
44 "fmt"
55 "os"
6- "slices"
76 "strings"
87
98 "github.com/charmbracelet/bubbles/list"
@@ -16,15 +15,16 @@ var (
1615 selectedColor = lipgloss .Color ("#00ADD8" )
1716 cursorColor = lipgloss .Color ("#00ADD8" )
1817 borderColor = lipgloss .Color ("240" )
18+
19+ helpHeaderColor = lipgloss .Color ("#00ADD8" )
20+ helpKeyColor = lipgloss .Color ("#5DC9E2" )
1921)
2022
2123var (
2224 selectedLabelStyle = lipgloss .NewStyle ().Foreground (selectedColor )
2325 selectedNameStyle = lipgloss .NewStyle ().Foreground (selectedColor ).Bold (true )
2426 selectedPathStyle = lipgloss .NewStyle ().Foreground (selectedColor ).Bold (true )
2527
26- helpHeaderStyle = lipgloss .NewStyle ().Foreground (selectedColor )
27-
2828 headerStyle = lipgloss .NewStyle ().
2929 Padding (0 , 2 ).
3030 Border (lipgloss .NormalBorder (), false , false , true , false ).
3939 Padding (0 , 1 ).
4040 Border (lipgloss .NormalBorder (), true , false , false , false ).
4141 BorderForeground (borderColor )
42+
43+ helpHeaderStyle = lipgloss .NewStyle ().Foreground (helpHeaderColor )
44+
45+ helpContentStyle = lipgloss .NewStyle ().Padding (0 , 2 )
46+ helpKeyStyle = lipgloss .NewStyle ().Foreground (helpKeyColor ).Bold (true )
4247)
4348
4449type view int
@@ -315,9 +320,27 @@ func (m model) helpView() string {
315320 headerVersion := helpHeaderStyle .Render ("Version: " + tip .AppVersion )
316321 header := headerStyle .Width (m .w ).Render (headerProgramName + "\n " + headerVersion )
317322
318- // todo
319- lines := slices .Repeat ([]string {"" }, m .h - 5 )
320- content := strings .Join (lines , "\n " )
323+ contentHeight := m .h - 5
324+ helps := helpItems ()
325+ keyLines := []string {}
326+ for _ , h := range helps {
327+ keys := make ([]string , 0 , len (h .keys ))
328+ for _ , k := range h .keys {
329+ keys = append (keys , "<" + helpKeyStyle .Render (k )+ ">" )
330+ }
331+ keyLine := strings .Join (keys , ", " ) + " : "
332+ keyLines = append (keyLines , keyLine )
333+ }
334+ descLines := []string {}
335+ for _ , h := range helps {
336+ descLines = append (descLines , h .desc )
337+ }
338+ lines := lipgloss .JoinHorizontal (lipgloss .Top ,
339+ lipgloss .JoinVertical (lipgloss .Right , keyLines ... ),
340+ lipgloss .JoinVertical (lipgloss .Left , descLines ... ),
341+ )
342+ padLines := strings .Repeat ("\n " , contentHeight - lipgloss .Height (lines ))
343+ content := helpContentStyle .Render (lines + padLines )
321344
322345 footerView := footerDividerStyle .Render (" | " ) + footerMsgStyle .Render ("Help " )
323346
@@ -329,6 +352,28 @@ func (m model) helpView() string {
329352 return lipgloss .JoinVertical (lipgloss .Left , header , content , footer )
330353}
331354
355+ type helpItem struct {
356+ keys []string
357+ desc string
358+ }
359+
360+ func helpItems () []helpItem {
361+ return []helpItem {
362+ {keys : []string {"Ctrl-c" }, desc : "Quit" },
363+ {keys : []string {"Down" , "j" }, desc : "Select next item" },
364+ {keys : []string {"Up" , "k" }, desc : "Select previous item" },
365+ {keys : []string {"Right" , "l" }, desc : "Select next page" },
366+ {keys : []string {"Left" , "h" }, desc : "Select previous page" },
367+ {keys : []string {"Enter" }, desc : "Run the selected test / Confirm filter (in filtering mode)" },
368+ {keys : []string {"Backspace" }, desc : "Select parent test group" },
369+ {keys : []string {"/" }, desc : "Enter filtering mode" },
370+ {keys : []string {"Esc" }, desc : "Clear filtering mode" },
371+ {keys : []string {"Ctrl-x" }, desc : "Toggle filtering type" },
372+ {keys : []string {"Tab" }, desc : "Switch view" },
373+ {keys : []string {"?" }, desc : "Show help" },
374+ }
375+ }
376+
332377func Start (
333378 tests map [string ][]* tip.TestFunction ,
334379 histories * tip.Histories ,
0 commit comments