aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--bug/label.go7
-rw-r--r--bug/label_test.go10
-rw-r--r--termui/bug_table.go13
-rw-r--r--termui/help_bar.go30
-rw-r--r--termui/label_select.go11
-rw-r--r--termui/show_bug.go12
7 files changed, 69 insertions, 16 deletions
diff --git a/README.md b/README.md
index 91917671..d75dfc68 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ That's all !
Install via the package manager
```
- pkg install git-bugs
+ pkg install git-bug
```
Or from the ports collection
diff --git a/bug/label.go b/bug/label.go
index 75d6b012..9d1e99a7 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -1,13 +1,14 @@
package bug
import (
- "crypto/sha1"
+ "crypto/sha256"
"fmt"
"image/color"
"strings"
- "github.com/MichaelMure/git-bug/util/text"
fcolor "github.com/fatih/color"
+
+ "github.com/MichaelMure/git-bug/util/text"
)
type Label string
@@ -42,7 +43,7 @@ func (l Label) Color() LabelColor {
}
id := 0
- hash := sha1.Sum([]byte(l))
+ hash := sha256.Sum256([]byte(l))
for _, char := range hash {
id = (id + int(char)) % len(colors)
}
diff --git a/bug/label_test.go b/bug/label_test.go
index 225e1352..49401c49 100644
--- a/bug/label_test.go
+++ b/bug/label_test.go
@@ -7,22 +7,22 @@ import (
)
func TestLabelRGBA(t *testing.T) {
- rgba := Label("test").Color()
- expected := LabelColor{R: 255, G: 87, B: 34, A: 255}
+ rgba := Label("test1").Color()
+ expected := LabelColor{R: 0, G: 150, B: 136, A: 255}
require.Equal(t, expected, rgba)
}
func TestLabelRGBASimilar(t *testing.T) {
- rgba := Label("test1").Color()
- expected := LabelColor{R: 0, G: 188, B: 212, A: 255}
+ rgba := Label("test2").Color()
+ expected := LabelColor{R: 3, G: 169, B: 244, A: 255}
require.Equal(t, expected, rgba)
}
func TestLabelRGBAReverse(t *testing.T) {
rgba := Label("tset").Color()
- expected := LabelColor{R: 233, G: 30, B: 99, A: 255}
+ expected := LabelColor{R: 63, G: 81, B: 181, A: 255}
require.Equal(t, expected, rgba)
}
diff --git a/termui/bug_table.go b/termui/bug_table.go
index 4c7ade77..b2361907 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(maxX))
}
_, err = g.SetCurrentView(bugTableView)
diff --git a/termui/help_bar.go b/termui/help_bar.go
new file mode 100644
index 00000000..78f8ebca
--- /dev/null
+++ b/termui/help_bar.go
@@ -0,0 +1,30 @@
+package termui
+
+import (
+ "fmt"
+ "strings"
+
+ text "github.com/MichaelMure/go-term-text"
+
+ "github.com/MichaelMure/git-bug/util/colors"
+)
+
+type helpBar []struct {
+ keys string
+ text string
+}
+
+func (hb helpBar) Render(maxX int) string {
+ var builder strings.Builder
+ 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 db0486e4..dfba20a6 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(maxX))
if _, err = g.SetViewOnTop(labelSelectInstructionsView); err != nil {
return err
}
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 23b82c73..6296c445 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(maxX))
_, err = g.SetViewOnTop(showBugInstructionView)
if err != nil {