|
|
|
@ -3,6 +3,7 @@ package searchapp |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"log" |
|
|
|
"log" |
|
|
|
|
|
|
|
"math" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
@ -46,7 +47,7 @@ type ItemColumns struct { |
|
|
|
Date string |
|
|
|
Date string |
|
|
|
|
|
|
|
|
|
|
|
// [host:]pwd
|
|
|
|
// [host:]pwd
|
|
|
|
HostWithColor string |
|
|
|
differentHost bool |
|
|
|
Host string |
|
|
|
Host string |
|
|
|
PwdTilde string |
|
|
|
PwdTilde string |
|
|
|
samePwd bool |
|
|
|
samePwd bool |
|
|
|
@ -132,7 +133,6 @@ func (i Item) DrawItemColumns(compactRendering bool, debug bool) ItemColumns { |
|
|
|
DateWithColor: notAvailable + " ", |
|
|
|
DateWithColor: notAvailable + " ", |
|
|
|
// dateWithColor: highlightDate(notAvailable) + " ",
|
|
|
|
// dateWithColor: highlightDate(notAvailable) + " ",
|
|
|
|
Host: "", |
|
|
|
Host: "", |
|
|
|
HostWithColor: "", |
|
|
|
|
|
|
|
PwdTilde: notAvailable, |
|
|
|
PwdTilde: notAvailable, |
|
|
|
CmdLine: i.CmdLine, |
|
|
|
CmdLine: i.CmdLine, |
|
|
|
CmdLineWithColor: i.CmdLineWithColor, |
|
|
|
CmdLineWithColor: i.CmdLineWithColor, |
|
|
|
@ -157,10 +157,8 @@ func (i Item) DrawItemColumns(compactRendering bool, debug bool) ItemColumns { |
|
|
|
// DISPLAY > location
|
|
|
|
// DISPLAY > location
|
|
|
|
// DISPLAY > location > host
|
|
|
|
// DISPLAY > location > host
|
|
|
|
host := "" |
|
|
|
host := "" |
|
|
|
hostWithColor := "" |
|
|
|
|
|
|
|
if i.differentHost { |
|
|
|
if i.differentHost { |
|
|
|
host += i.host + ":" |
|
|
|
host += i.host |
|
|
|
hostWithColor += highlightHost(i.host) + ":" |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// DISPLAY > location > directory
|
|
|
|
// DISPLAY > location > directory
|
|
|
|
pwdTilde := strings.Replace(i.pwd, i.home, "~", 1) |
|
|
|
pwdTilde := strings.Replace(i.pwd, i.home, "~", 1) |
|
|
|
@ -188,9 +186,9 @@ func (i Item) DrawItemColumns(compactRendering bool, debug bool) ItemColumns { |
|
|
|
Date: date, |
|
|
|
Date: date, |
|
|
|
DateWithColor: dateWithColor, |
|
|
|
DateWithColor: dateWithColor, |
|
|
|
Host: host, |
|
|
|
Host: host, |
|
|
|
HostWithColor: hostWithColor, |
|
|
|
|
|
|
|
PwdTilde: pwdTilde, |
|
|
|
PwdTilde: pwdTilde, |
|
|
|
samePwd: i.samePwd, |
|
|
|
samePwd: i.samePwd, |
|
|
|
|
|
|
|
differentHost: i.differentHost, |
|
|
|
Flags: flags, |
|
|
|
Flags: flags, |
|
|
|
FlagsWithColor: flagsWithColor, |
|
|
|
FlagsWithColor: flagsWithColor, |
|
|
|
CmdLine: i.CmdLine, |
|
|
|
CmdLine: i.CmdLine, |
|
|
|
@ -200,27 +198,63 @@ func (i Item) DrawItemColumns(compactRendering bool, debug bool) ItemColumns { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func minInt(values ...int) int { |
|
|
|
|
|
|
|
min := math.MaxInt32 |
|
|
|
|
|
|
|
for _, val := range values { |
|
|
|
|
|
|
|
if val < min { |
|
|
|
|
|
|
|
min = val |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return min |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func produceLocation(length int, host string, pwdTilde string, differentHost bool, samePwd bool, debug bool) string { |
|
|
|
|
|
|
|
hostLen := len(host) |
|
|
|
|
|
|
|
if hostLen <= 0 { |
|
|
|
|
|
|
|
pwdWithColor := leftCutPadString(pwdTilde, length) |
|
|
|
|
|
|
|
if samePwd { |
|
|
|
|
|
|
|
pwdWithColor = highlightPwd(pwdWithColor) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pwdWithColor |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
colonLen := 1 |
|
|
|
|
|
|
|
pwdLen := len(pwdTilde) |
|
|
|
|
|
|
|
totalLen := hostLen + colonLen + pwdLen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// how much we need to shrink/crop the location
|
|
|
|
|
|
|
|
shrinkFactor := float32(length) / float32(totalLen) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shrinkedHostLen := int(float32(hostLen) * shrinkFactor) |
|
|
|
|
|
|
|
if debug { |
|
|
|
|
|
|
|
log.Printf("shrinkFactor: %f\n", shrinkFactor) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
halfLocationLen := length/2 - colonLen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newHostLen := minInt(hostLen, shrinkedHostLen, halfLocationLen) |
|
|
|
|
|
|
|
newPwdLen := length - colonLen - newHostLen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hostWithColor := rightCutPadString(host, newHostLen) |
|
|
|
|
|
|
|
if differentHost { |
|
|
|
|
|
|
|
hostWithColor = highlightHost(hostWithColor) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pwdWithColor := leftCutPadString(pwdTilde, newPwdLen) |
|
|
|
|
|
|
|
if samePwd { |
|
|
|
|
|
|
|
pwdWithColor = highlightPwd(pwdWithColor) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return hostWithColor + ":" + pwdWithColor |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ProduceLine ...
|
|
|
|
// ProduceLine ...
|
|
|
|
func (ic ItemColumns) ProduceLine(dateLength int, locationLength int, flagLength int, header bool, showDate bool) (string, int) { |
|
|
|
func (ic ItemColumns) ProduceLine(dateLength int, locationLength int, flagLength int, header bool, showDate bool, debug bool) (string, int) { |
|
|
|
line := "" |
|
|
|
line := "" |
|
|
|
if showDate { |
|
|
|
if showDate { |
|
|
|
line += strings.Repeat(" ", dateLength-len(ic.Date)) + ic.DateWithColor |
|
|
|
line += strings.Repeat(" ", dateLength-len(ic.Date)) + ic.DateWithColor |
|
|
|
} |
|
|
|
} |
|
|
|
// LOCATION
|
|
|
|
// LOCATION
|
|
|
|
var locationWithColor string |
|
|
|
locationWithColor := produceLocation(locationLength, ic.Host, ic.PwdTilde, ic.differentHost, ic.samePwd, debug) |
|
|
|
// ensure that host will not take up all the space
|
|
|
|
|
|
|
|
if len(ic.Host) >= locationLength { |
|
|
|
|
|
|
|
locationWithColor = rightCutPadString(ic.Host, locationLength / 2 - 1) + ":" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
locationWithColor = ic.HostWithColor |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pwdLength := locationLength - len(locationWithColor) |
|
|
|
|
|
|
|
if ic.samePwd { |
|
|
|
|
|
|
|
locationWithColor += highlightPwd(leftCutPadString(ic.PwdTilde, pwdLength)) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
locationWithColor += leftCutPadString(ic.PwdTilde, pwdLength) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
line += locationWithColor |
|
|
|
line += locationWithColor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FLAGS
|
|
|
|
line += ic.FlagsWithColor |
|
|
|
line += ic.FlagsWithColor |
|
|
|
flags := ic.Flags |
|
|
|
flags := ic.Flags |
|
|
|
if flagLength < len(ic.Flags) { |
|
|
|
if flagLength < len(ic.Flags) { |
|
|
|
@ -402,7 +436,7 @@ func NewItemFromRecordForQuery(record records.CliRecord, query Query, debug bool |
|
|
|
// GetHeader returns header columns
|
|
|
|
// GetHeader returns header columns
|
|
|
|
func GetHeader(compactRendering bool) ItemColumns { |
|
|
|
func GetHeader(compactRendering bool) ItemColumns { |
|
|
|
date := "TIME " |
|
|
|
date := "TIME " |
|
|
|
host := "HOST:" |
|
|
|
host := "HOST" |
|
|
|
dir := "DIRECTORY" |
|
|
|
dir := "DIRECTORY" |
|
|
|
if compactRendering { |
|
|
|
if compactRendering { |
|
|
|
dir = "DIR" |
|
|
|
dir = "DIR" |
|
|
|
@ -413,7 +447,6 @@ func GetHeader(compactRendering bool) ItemColumns { |
|
|
|
Date: date, |
|
|
|
Date: date, |
|
|
|
DateWithColor: date, |
|
|
|
DateWithColor: date, |
|
|
|
Host: host, |
|
|
|
Host: host, |
|
|
|
HostWithColor: host, |
|
|
|
|
|
|
|
PwdTilde: dir, |
|
|
|
PwdTilde: dir, |
|
|
|
samePwd: false, |
|
|
|
samePwd: false, |
|
|
|
Flags: flags, |
|
|
|
Flags: flags, |
|
|
|
|