Fix execute and paste in raw mode

pull/195/head v3.0.0-rc3
Šimon Let 3 years ago
parent 7da16a6bf6
commit 9320e90b25
  1. 32
      internal/searchapp/item.go

@ -61,6 +61,7 @@ type ItemColumns struct {
FlagsWithColor string FlagsWithColor string
Flags string Flags string
// Shown in TUI
CmdLineWithColor string CmdLineWithColor string
CmdLine string CmdLine string
@ -334,6 +335,14 @@ func properMatch(str, term, padChar string) bool {
return strings.Contains(padChar+str+padChar, padChar+term+padChar) return strings.Contains(padChar+str+padChar, padChar+term+padChar)
} }
func trimCmdLine(cmdLine string) string {
return strings.TrimRightFunc(cmdLine, unicode.IsSpace)
}
func replaceNewLines(cmdLine string) string {
return strings.ReplaceAll(cmdLine, "\n", "\\n ")
}
// NewItemFromRecordForQuery creates new item from record based on given query // NewItemFromRecordForQuery creates new item from record based on given query
// //
// returns error if the query doesn't match the record // returns error if the query doesn't match the record
@ -363,7 +372,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
// nonZeroExitCodeScorePenalty + differentHostScorePenalty // nonZeroExitCodeScorePenalty + differentHostScorePenalty
// Trim trailing whitespace before highlighting // Trim trailing whitespace before highlighting
trimmedCmdLine := strings.TrimRightFunc(record.CmdLine, unicode.IsSpace) trimmedCmdLine := trimCmdLine(record.CmdLine)
// KEY for deduplication // KEY for deduplication
key := trimmedCmdLine key := trimmedCmdLine
@ -385,8 +394,8 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo
// DISPLAY > cmdline // DISPLAY > cmdline
// cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">"
cmdLine := strings.ReplaceAll(trimmedCmdLine, "\n", "\\n ") cmdLine := replaceNewLines(trimmedCmdLine)
cmdLineWithColor := strings.ReplaceAll(cmd, "\n", "\\n ") cmdLineWithColor := replaceNewLines(cmd)
if record.IsRaw { if record.IsRaw {
return Item{ return Item{
@ -483,6 +492,7 @@ func GetHeader(compactRendering bool) ItemColumns {
type RawItem struct { type RawItem struct {
CmdLineWithColor string CmdLineWithColor string
CmdLine string CmdLine string
// Unchanged cmdline to paste to command line
CmdLineOut string CmdLineOut string
Score float64 Score float64
@ -501,8 +511,14 @@ func NewRawItemFromRecordForQuery(record recordint.SearchApp, terms []string, de
const timeScoreCoef = 1e-13 const timeScoreCoef = 1e-13
// Trim trailing whitespace before highlighting
trimmedCmdLine := strings.TrimRightFunc(record.CmdLine, unicode.IsSpace)
// KEY for deduplication
key := trimmedCmdLine
score := 0.0 score := 0.0
cmd := record.CmdLine cmd := trimmedCmdLine
for _, term := range terms { for _, term := range terms {
c := strings.Count(record.CmdLine, term) c := strings.Count(record.CmdLine, term)
if c > 0 { if c > 0 {
@ -514,16 +530,14 @@ func NewRawItemFromRecordForQuery(record recordint.SearchApp, terms []string, de
} }
} }
score += record.Time * timeScoreCoef score += record.Time * timeScoreCoef
// KEY for deduplication
key := record.CmdLine
// DISPLAY > cmdline // DISPLAY > cmdline
// cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">"
cmdLine := strings.ReplaceAll(record.CmdLine, "\n", ";") cmdLine := replaceNewLines(trimmedCmdLine)
cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") cmdLineWithColor := replaceNewLines(cmd)
it := RawItem{ it := RawItem{
CmdLineOut: record.CmdLine,
CmdLine: cmdLine, CmdLine: cmdLine,
CmdLineWithColor: cmdLineWithColor, CmdLineWithColor: cmdLineWithColor,
Score: score, Score: score,

Loading…
Cancel
Save