add time and pwd to the status line

pull/137/head
Simon Let 6 years ago
parent 45cded18f2
commit 643805e245
  1. 46
      cmd/cli/item.go
  2. 29
      cmd/cli/main.go

@ -68,6 +68,52 @@ func (i item) less(i2 item) bool {
return i.score > i2.score
}
func splitStatusLineToLines(statusLine string, printedLineLength, realLineLength int) []string {
var statusLineSlice []string
// status line
var idxSt, idxEnd int
var nextLine bool
tab := " "
tabSize := len(tab)
for idxSt < len(statusLine) {
idxEnd = idxSt + printedLineLength
if nextLine {
idxEnd -= tabSize
}
if idxEnd > len(statusLine) {
idxEnd = len(statusLine)
}
str := statusLine[idxSt:idxEnd]
indent := " "
if nextLine {
indent += tab
}
statusLineSlice = append(statusLineSlice, highlightStatus(rightCutPadString(indent+str, realLineLength))+"\n")
idxSt += printedLineLength
nextLine = true
}
return statusLineSlice
}
func (i item) drawStatusLine(compactRendering bool, printedLineLength, realLineLength int) []string {
if i.isRaw {
return splitStatusLineToLines(" "+i.cmdLine, printedLineLength, realLineLength)
}
secs := int64(i.realtimeBefore)
nsecs := int64((i.realtimeBefore - float64(secs)) * 1e9)
tm := time.Unix(secs, nsecs)
const timeFormat = "2006-01-02 15:04:05"
timeString := tm.Format(timeFormat)
pwdTilde := strings.Replace(i.pwd, i.home, "~", 1)
separator := " "
stLine := timeString + separator + pwdTilde + separator + i.cmdLine
return splitStatusLineToLines(stLine, printedLineLength, realLineLength)
}
func (i item) drawItemColumns(compactRendering bool) itemColumns {
if i.isRaw {
notAvailable := "n/a"

@ -487,8 +487,8 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
topBoxHeight++ // headers
realLineLength := maxX - 2
printedLineLength := maxX - 4
selectedCommand := m.s.data[m.s.highlightedItem].cmdLine
var statusLineHeight int = len(selectedCommand)/(printedLineLength) + 1
statusLine := m.s.data[m.s.highlightedItem].drawStatusLine(compactRenderingMode, printedLineLength, realLineLength)
var statusLineHeight int = len(statusLine) + 1 // help line
helpLineHeight := 1
const helpLine = "HELP: type to search, UP/DOWN to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; " +
@ -536,29 +536,8 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
v.WriteString("\n")
index++
}
// 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
for _, line := range statusLine {
v.WriteString(line)
}
v.WriteString(helpLine)
if debug {

Loading…
Cancel
Save