From 9ce84fc1a310e04ab63661f5fc3963a9de317981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 12 Apr 2020 11:11:01 +0200 Subject: [PATCH 1/2] termui: make the help visually easier to parse --- termui/bug_table.go | 13 +++++++++++-- termui/help_bar.go | 24 ++++++++++++++++++++++++ termui/label_select.go | 11 ++++++++--- termui/show_bug.go | 12 ++++++++++-- 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 termui/help_bar.go diff --git a/termui/bug_table.go b/termui/bug_table.go index 4c7ade77..d4e4552e 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -23,6 +23,16 @@ const bugTableInstructionView = "bugTableInstructionView" const defaultRemote = "origin" const defaultQuery = "status:open" +var bugTableHelp = helpBar{ + {"q", "Quit"}, + {"s", "Search"}, + {"←↓↑→,hjkl", "Navigation"}, + {"↵", "Open bug"}, + {"n", "New bug"}, + {"i", "Pull"}, + {"o", "Push"}, +} + type bugTable struct { repo *cache.RepoCache queryStr string @@ -117,9 +127,8 @@ func (bt *bugTable) layout(g *gocui.Gui) error { v.Frame = false v.FgColor = gocui.ColorWhite - v.BgColor = gocui.ColorBlue - _, _ = fmt.Fprintf(v, "[q] Quit [s] Search [←↓↑→,hjkl] Navigation [↵] Open bug [n] New bug [i] Pull [o] Push") + _, _ = fmt.Fprint(v, bugTableHelp.Render()) } _, err = g.SetCurrentView(bugTableView) diff --git a/termui/help_bar.go b/termui/help_bar.go new file mode 100644 index 00000000..eb6facb6 --- /dev/null +++ b/termui/help_bar.go @@ -0,0 +1,24 @@ +package termui + +import ( + "fmt" + "strings" + + "github.com/MichaelMure/git-bug/util/colors" +) + +type helpBar []struct { + keys string + text string +} + +func (hb helpBar) Render() string { + var builder strings.Builder + for i, entry := range hb { + if i != 0 { + builder.WriteByte(' ') + } + builder.WriteString(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))) + } + return builder.String() +} diff --git a/termui/label_select.go b/termui/label_select.go index db0486e4..dc5adc2e 100644 --- a/termui/label_select.go +++ b/termui/label_select.go @@ -13,6 +13,12 @@ import ( const labelSelectView = "labelSelectView" const labelSelectInstructionsView = "labelSelectInstructionsView" +var labelSelectHelp = helpBar{ + {"q", "Save and close"}, + {"↓↑,jk", "Nav"}, + {"a", "Add item"}, +} + type labelSelect struct { cache *cache.RepoCache bug *cache.BugCache @@ -132,7 +138,7 @@ func (ls *labelSelect) layout(g *gocui.Gui) error { lc := label.Color() lc256 := lc.Term256() labelStr := lc256.Escape() + "◼ " + lc256.Unescape() + label.String() - fmt.Fprint(v, selectBox, labelStr) + _, _ = fmt.Fprint(v, selectBox, labelStr) y0 += 2 } @@ -145,10 +151,9 @@ func (ls *labelSelect) layout(g *gocui.Gui) error { } v.Frame = false v.FgColor = gocui.ColorWhite - v.BgColor = gocui.ColorBlue } v.Clear() - fmt.Fprint(v, "[q] Save and close [↓↑,jk] Nav [a] Add item") + _, _ = fmt.Fprint(v, labelSelectHelp.Render()) if _, err = g.SetViewOnTop(labelSelectInstructionsView); err != nil { return err } diff --git a/termui/show_bug.go b/termui/show_bug.go index 23b82c73..74eccd36 100644 --- a/termui/show_bug.go +++ b/termui/show_bug.go @@ -21,6 +21,15 @@ const showBugHeaderView = "showBugHeaderView" const timeLayout = "Jan 2 2006" +var showBugHelp = helpBar{ + {"q", "Save and return"}, + {"←↓↑→,hjkl", "Navigation"}, + {"o", "Toggle open/close"}, + {"e", "Edit"}, + {"c", "Comment"}, + {"t", "Change title"}, +} + type showBug struct { cache *cache.RepoCache bug *cache.BugCache @@ -93,11 +102,10 @@ func (sb *showBug) layout(g *gocui.Gui) error { sb.childViews = append(sb.childViews, showBugInstructionView) v.Frame = false v.FgColor = gocui.ColorWhite - v.BgColor = gocui.ColorBlue } v.Clear() - _, _ = fmt.Fprintf(v, "[q] Save and return [←↓↑→,hjkl] Navigation [o] Toggle open/close [e] Edit [c] Comment [t] Change title") + _, _ = fmt.Fprint(v, showBugHelp.Render()) _, err = g.SetViewOnTop(showBugInstructionView) if err != nil { From 8eb7faf67c403e9692fa7faa0a3f2d74fa774330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sat, 22 Aug 2020 15:27:57 +0200 Subject: [PATCH 2/2] termui: help bar background goes all the width --- termui/bug_table.go | 2 +- termui/help_bar.go | 16 +++++++++++----- termui/label_select.go | 2 +- termui/show_bug.go | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/termui/bug_table.go b/termui/bug_table.go index d4e4552e..b2361907 100644 --- a/termui/bug_table.go +++ b/termui/bug_table.go @@ -128,7 +128,7 @@ func (bt *bugTable) layout(g *gocui.Gui) error { v.Frame = false v.FgColor = gocui.ColorWhite - _, _ = fmt.Fprint(v, bugTableHelp.Render()) + _, _ = fmt.Fprint(v, bugTableHelp.Render(maxX)) } _, err = g.SetCurrentView(bugTableView) diff --git a/termui/help_bar.go b/termui/help_bar.go index eb6facb6..78f8ebca 100644 --- a/termui/help_bar.go +++ b/termui/help_bar.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + text "github.com/MichaelMure/go-term-text" + "github.com/MichaelMure/git-bug/util/colors" ) @@ -12,13 +14,17 @@ type helpBar []struct { text string } -func (hb helpBar) Render() string { +func (hb helpBar) Render(maxX int) string { var builder strings.Builder - for i, entry := range hb { - if i != 0 { - builder.WriteByte(' ') - } + for _, entry := range hb { builder.WriteString(colors.BlueBg(fmt.Sprintf("[%s] %s", entry.keys, entry.text))) + builder.WriteByte(' ') } + + l := text.Len(builder.String()) + if l < maxX { + builder.WriteString(colors.BlueBg(strings.Repeat(" ", maxX-l))) + } + return builder.String() } diff --git a/termui/label_select.go b/termui/label_select.go index dc5adc2e..dfba20a6 100644 --- a/termui/label_select.go +++ b/termui/label_select.go @@ -153,7 +153,7 @@ func (ls *labelSelect) layout(g *gocui.Gui) error { v.FgColor = gocui.ColorWhite } v.Clear() - _, _ = fmt.Fprint(v, labelSelectHelp.Render()) + _, _ = fmt.Fprint(v, labelSelectHelp.Render(maxX)) if _, err = g.SetViewOnTop(labelSelectInstructionsView); err != nil { return err } diff --git a/termui/show_bug.go b/termui/show_bug.go index 74eccd36..6296c445 100644 --- a/termui/show_bug.go +++ b/termui/show_bug.go @@ -105,7 +105,7 @@ func (sb *showBug) layout(g *gocui.Gui) error { } v.Clear() - _, _ = fmt.Fprint(v, showBugHelp.Render()) + _, _ = fmt.Fprint(v, showBugHelp.Render(maxX)) _, err = g.SetViewOnTop(showBugInstructionView) if err != nil {