diff --git a/README.md b/README.md index 4e15f5d..cf235a7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Ensure you have your latest graphics card drivers installed before use. ## Contextual Hints -![Example hint](hint.png) +![Permissions hint](hint.png) +![Colour hex hint](hint.colour.png) ## Built-in Powerline Fonts diff --git a/gui/explain.go b/gui/explain.go index a206b71..a8f7705 100644 --- a/gui/explain.go +++ b/gui/explain.go @@ -41,6 +41,6 @@ func (a *annotation) render(gui *GUI) { } } - gui.textbox(a.hint.StartX+1, a.hint.StartY+3, a.hint.Description) + gui.textbox(a.hint.StartX+1, a.hint.StartY+3, a.hint.Description, a.hint.ForegroundColour, a.hint.BackgroundColour) } diff --git a/gui/gui.go b/gui/gui.go index e9709c2..4a4e5aa 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -265,7 +265,10 @@ Buffer Size: %d lines gui.terminal.ActiveBuffer().ViewWidth(), gui.terminal.ActiveBuffer().ViewHeight(), gui.terminal.ActiveBuffer().Height(), - )) + ), + [3]float32{0, 1, 0}, + [3]float32{0, 0, 0}, + ) } gui.window.SwapBuffers() diff --git a/gui/mouse.go b/gui/mouse.go index 208bdfa..99aba12 100644 --- a/gui/mouse.go +++ b/gui/mouse.go @@ -27,13 +27,11 @@ func (gui *GUI) mouseMoveCallback(w *glfw.Window, xpos float64, ypos float64) { gui.terminal.ActiveBuffer().EndSelection(x, y, false) } else { - if gui.terminal.UsingMainBuffer() { - hint := gui.terminal.ActiveBuffer().GetHintAtPosition(x, y) - if hint != nil { - gui.setOverlay(newAnnotation(hint)) - } else { - gui.setOverlay(nil) - } + hint := gui.terminal.ActiveBuffer().GetHintAtPosition(x, y) + if hint != nil { + gui.setOverlay(newAnnotation(hint)) + } else { + gui.setOverlay(nil) } } diff --git a/gui/overlays.go b/gui/overlays.go index 0aa996f..e1d32dc 100644 --- a/gui/overlays.go +++ b/gui/overlays.go @@ -10,7 +10,7 @@ func (gui *GUI) setOverlay(m overlay) { } func (gui *GUI) renderOverlay() { - if gui.overlay == nil || !gui.terminal.UsingMainBuffer() { + if gui.overlay == nil { return } diff --git a/gui/textbox.go b/gui/textbox.go index 9fe6dd2..c56c526 100644 --- a/gui/textbox.go +++ b/gui/textbox.go @@ -6,7 +6,7 @@ import ( "github.com/liamg/aminal/buffer" ) -func (gui *GUI) textbox(col uint16, row uint16, text string) { +func (gui *GUI) textbox(col uint16, row uint16, text string, fg [3]float32, bg [3]float32) { lines := []string{} line := "" @@ -81,18 +81,16 @@ DONE: gui.renderer.Clean() - bg := [3]float32{0, 0, 0} - - for hx := col; hx < col+uint16(longestLine)+2; hx++ { + for hx := col; hx < col+uint16(longestLine)+1; hx++ { for hy := row - 1; hy < row+uint16(len(lines))+1; hy++ { - gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), false, nil , true) + gui.renderer.DrawCellBg(buffer.NewBackgroundCell(bg), uint(hx), uint(hy), false, nil, true) } } x := float32(col) * gui.renderer.cellWidth f := gui.fontMap.GetFont('X') - f.SetColor(0.2, 1, 0.2, 1) + f.SetColor(fg[0], fg[1], fg[2], 1) for i, line := range lines { y := float32(row+1+uint16(i)) * gui.renderer.cellHeight diff --git a/hint.colour.png b/hint.colour.png new file mode 100644 index 0000000..c0ec105 Binary files /dev/null and b/hint.colour.png differ diff --git a/hints/colours.go b/hints/colours.go new file mode 100644 index 0000000..ac9fb9f --- /dev/null +++ b/hints/colours.go @@ -0,0 +1,47 @@ +package hints + +import ( + "regexp" + "strconv" +) + +func init() { + hinters = append(hinters, hintColours) +} + +func hintColours(word string, context string, wordX uint16, wordY uint16) *Hint { + + item := NewHint(word, context, wordX, wordY) + + if isColour(word) { + + r, err := strconv.ParseInt(word[1:3], 16, 64) + if err != nil { + return nil + } + g, err := strconv.ParseInt(word[3:5], 16, 64) + if err != nil { + return nil + } + b, err := strconv.ParseInt(word[5:7], 16, 64) + if err != nil { + return nil + } + + item.Description = word + item.BackgroundColour = [3]float32{float32(r) / 255, float32(g) / 255, float32(b) / 255} + if (r+g+b)/3 < 128 { + item.ForegroundColour = [3]float32{1, 1, 1} + } else { + item.ForegroundColour = [3]float32{0, 0, 0} + } + return item + } + + return nil +} + +func isColour(s string) bool { + re := regexp.MustCompile("#[0-9A-Fa-f]{6}") + return re.MatchString(s) +} diff --git a/hints/hint.go b/hints/hint.go index 89866a7..289053d 100644 --- a/hints/hint.go +++ b/hints/hint.go @@ -1,11 +1,13 @@ package hints type Hint struct { - Word string - StartX uint16 - StartY uint16 - Line string - Description string + Word string + StartX uint16 + StartY uint16 + Line string + Description string + BackgroundColour [3]float32 + ForegroundColour [3]float32 } type hinter func(word string, context string, wordX uint16, wordY uint16) *Hint @@ -20,3 +22,14 @@ func Get(word string, context string, wordX uint16, wordY uint16) *Hint { } return nil } + +func NewHint(word string, context string, wordX uint16, wordY uint16) *Hint { + return &Hint{ + Line: context, + Word: word, + StartX: wordX, + StartY: wordY, + BackgroundColour: [3]float32{0, 0, 0}, + ForegroundColour: [3]float32{0.2, 1, 0.2}, + } +} diff --git a/hints/perms.go b/hints/perms.go index 57454ce..49fc0fa 100644 --- a/hints/perms.go +++ b/hints/perms.go @@ -112,12 +112,7 @@ func init() { func hintPerms(word string, context string, wordX uint16, wordY uint16) *Hint { - item := &Hint{ - Line: context, - Word: word, - StartX: wordX, - StartY: wordY, - } + item := NewHint(word, context, wordX, wordY) if wordX == 0 {