add simple status line

pull/137/head
Simon Let 6 years ago
parent 877dfa6345
commit e5a2279505
  1. 6
      cmd/cli/highlight.go
  2. 35
      cmd/cli/main.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"

@ -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)

Loading…
Cancel
Save