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 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 { func highlightHost(str string) string {
// template "\033[3%d;%dm" // template "\033[3%d;%dm"
redNormal := "\033[31m" redNormal := "\033[31m"

@ -6,13 +6,14 @@ import (
"log" "log"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/curusarn/resh/pkg/records" "github.com/curusarn/resh/pkg/records"
) )
type item struct { type item struct {
// dateWithColor string dateWithColor string
// date string date string
// [host:]pwd // [host:]pwd
locationWithColor string locationWithColor string
@ -36,8 +37,11 @@ func (i item) less(i2 item) bool {
return i.score > i2.score return i.score > i2.score
} }
func (i item) produceLine(flagLength int) (string, int) { func (i item) produceLine(flagLength int, showDate bool) (string, int) {
line := "" line := ""
if showDate {
line += i.dateWithColor
}
line += i.locationWithColor line += i.locationWithColor
line += i.flagsWithColor line += i.flagsWithColor
flags := i.flags flags := i.flags
@ -167,7 +171,11 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
// DISPLAY // DISPLAY
// DISPLAY > date // 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 // DISPLAY > location
location := "" location := ""
@ -213,6 +221,8 @@ func newItemFromRecordForQuery(record records.CliRecord, query query, debug bool
cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";")
it := item{ it := item{
date: date,
dateWithColor: dateWithColor,
location: location, location: location,
locationWithColor: locationWithColor, locationWithColor: locationWithColor,
flags: flags, flags: flags,

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

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

Loading…
Cancel
Save