From 643805e245835c747a9d71813f4d09ffa00d48b4 Mon Sep 17 00:00:00 2001 From: Simon Let Date: Sat, 9 May 2020 21:10:18 +0200 Subject: [PATCH] add time and pwd to the status line --- cmd/cli/item.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ cmd/cli/main.go | 29 ++++------------------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/cmd/cli/item.go b/cmd/cli/item.go index 50f2bcb..55c2b32 100644 --- a/cmd/cli/item.go +++ b/cmd/cli/item.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" diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 93b3ee4..c5c337e 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -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 {