From e5a2279505357c1ac75ee1350101870faadf8ed3 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Fri, 1 May 2020 23:02:22 +0200 Subject: [PATCH] add simple status line --- cmd/cli/highlight.go | 6 ++++++ cmd/cli/main.go | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cmd/cli/highlight.go b/cmd/cli/highlight.go index eabe539..6a8c39d 100644 --- a/cmd/cli/highlight.go +++ b/cmd/cli/highlight.go @@ -27,6 +27,12 @@ func cleanHighlight(str string) string { return str } +func highlightStatus(str string) string { + invert := "\033[7;1m" + end := "\033[0m" + return invert + cleanHighlight(str) + end +} + func highlightSelected(str string) string { // template "\033[3%d;%dm" // invertGreen := "\033[32;7;1m" diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 7fde661..70a1da9 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -440,8 +440,15 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { } } + // status line + topBoxSize := 3 // size of the query box up top + realLineLength := maxX - 2 + printedLineLength := maxX - 4 + selectedCommand := m.s.data[m.s.highlightedItem].cmdLine + var selectedLineCount int = len(selectedCommand)/(printedLineLength) + 1 + for i, itm := range m.s.data { - if i == maxY { + if i == maxY-topBoxSize-selectedLineCount { if debug { log.Println(maxY) } @@ -449,7 +456,7 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { } displayStr, _ := itm.produceLine(longestFlagsLen) if m.s.highlightedItem == i { - // use actual min requried length instead of 420 constant + // maxX * 2 because there are escape sequences that make it hard to tell the real string lenght displayStr = doHighlightString(displayStr, maxX*2) if debug { log.Println("### HightlightedItem string :", displayStr) @@ -469,6 +476,30 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error { // v.SetHighlight(m.s.highlightedItem, true) // } } + // status line + var idxSt, idxEnd int + var nextLine bool + tab := " " + tabSize := len(tab) + for idxSt < len(selectedCommand) { + idxEnd = idxSt + printedLineLength + if nextLine { + idxEnd -= tabSize + } + + if idxEnd > len(selectedCommand) { + idxEnd = len(selectedCommand) + } + str := selectedCommand[idxSt:idxEnd] + + indent := " " + if nextLine { + indent += tab + } + v.WriteString(highlightStatus(rightCutPadString(indent+str, realLineLength)) + "\n") + idxSt += printedLineLength + nextLine = true + } if debug { log.Println("len(data) =", len(m.s.data)) log.Println("highlightedItem =", m.s.highlightedItem)