show datetime in cli - experiment

pull/137/head
Simon Let 6 years ago
parent 52fc74c588
commit 617cc31fa3
  1. 7
      cmd/cli/highlight.go
  2. 18
      cmd/cli/item.go
  3. 2
      cmd/cli/main.go
  4. 17
      pkg/records/records.go

@ -41,6 +41,13 @@ func highlightSelected(str string) string {
return invert + cleanHighlight(str) + end
}
func highlightDate(str string) string {
// template "\033[3%d;%dm"
yellowNormal := "\033[33m"
end := "\033[0m"
return yellowNormal + cleanHighlight(str) + end
}
func highlightHost(str string) string {
// template "\033[3%d;%dm"
redNormal := "\033[31m"

@ -6,13 +6,14 @@ import (
"log"
"strconv"
"strings"
"time"
"github.com/curusarn/resh/pkg/records"
)
type item struct {
// dateWithColor string
// date string
dateWithColor string
date string
// [host:]pwd
locationWithColor string
@ -36,8 +37,11 @@ func (i item) less(i2 item) bool {
return i.score > i2.score
}
func (i item) produceLine(flagLength int) (string, int) {
func (i item) produceLine(flagLength int, showDate bool) (string, int) {
line := ""
if showDate {
line += i.dateWithColor
}
line += i.locationWithColor
line += i.flagsWithColor
flags := i.flags
@ -167,7 +171,11 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
// DISPLAY
// DISPLAY > date
// TODO
secs := int64(record.RealtimeBeforeLocal)
nsecs := int64((record.RealtimeBeforeLocal - float64(secs)) * 1e9)
tm := time.Unix(secs, nsecs)
date := tm.Format("2006-01-02_15:04 ")
dateWithColor := highlightDate(date)
// DISPLAY > location
location := ""
@ -213,6 +221,8 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";")
it := item{
date: date,
dateWithColor: dateWithColor,
location: location,
locationWithColor: locationWithColor,
flags: flags,

@ -456,7 +456,7 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
}
break
}
displayStr, _ := itm.produceLine(longestFlagsLen)
displayStr, _ := itm.produceLine(longestFlagsLen, true)
if m.s.highlightedItem == i {
// maxX * 2 because there are escape sequences that make it hard to tell the real string lenght
displayStr = doHighlightString(displayStr, maxX*2)

@ -158,7 +158,7 @@ type CliRecord struct {
GitOriginRemote string `json:"gitOriginRemote"`
ExitCode int `json:"exitCode"`
// RealtimeBefore float64 `json:"realtimeBefore"`
RealtimeBeforeLocal float64 `json:"realtimeBeforeLocal"`
// RealtimeAfter float64 `json:"realtimeAfter"`
// RealtimeDuration float64 `json:"realtimeDuration"`
}
@ -166,13 +166,14 @@ type CliRecord struct {
// NewCliRecord from EnrichedRecord
func NewCliRecord(r EnrichedRecord) CliRecord {
return CliRecord{
SessionID: r.SessionID,
CmdLine: r.CmdLine,
Host: r.Host,
Pwd: r.Pwd,
Home: r.Home,
GitOriginRemote: r.GitOriginRemote,
ExitCode: r.ExitCode,
SessionID: r.SessionID,
CmdLine: r.CmdLine,
Host: r.Host,
Pwd: r.Pwd,
Home: r.Home,
GitOriginRemote: r.GitOriginRemote,
ExitCode: r.ExitCode,
RealtimeBeforeLocal: r.RealtimeBeforeLocal,
}
}

Loading…
Cancel
Save