From 651ace4ec420d0beff0509969696d2996caf394d Mon Sep 17 00:00:00 2001 From: Simon Let Date: Sat, 25 Feb 2023 15:22:06 +0100 Subject: [PATCH] Output unmodified command lines from search Fixes: #152 --- cmd/cli/main.go | 8 ++++---- internal/searchapp/item.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 9e041cb..222f738 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -200,13 +200,13 @@ func (m manager) SelectExecute(g *gocui.Gui, v *gocui.View) error { defer m.s.lock.Unlock() if m.s.rawMode { if m.s.highlightedItem < len(m.s.rawData) { - m.s.output = m.s.rawData[m.s.highlightedItem].CmdLine + m.s.output = m.s.rawData[m.s.highlightedItem].CmdLineOut m.s.exitCode = exitCodeExecute return gocui.ErrQuit } } else { if m.s.highlightedItem < len(m.s.data) { - m.s.output = m.s.data[m.s.highlightedItem].CmdLine + m.s.output = m.s.data[m.s.highlightedItem].CmdLineOut m.s.exitCode = exitCodeExecute return gocui.ErrQuit } @@ -219,13 +219,13 @@ func (m manager) SelectPaste(g *gocui.Gui, v *gocui.View) error { defer m.s.lock.Unlock() if m.s.rawMode { if m.s.highlightedItem < len(m.s.rawData) { - m.s.output = m.s.rawData[m.s.highlightedItem].CmdLine + m.s.output = m.s.rawData[m.s.highlightedItem].CmdLineOut m.s.exitCode = 0 // success return gocui.ErrQuit } } else { if m.s.highlightedItem < len(m.s.data) { - m.s.output = m.s.data[m.s.highlightedItem].CmdLine + m.s.output = m.s.data[m.s.highlightedItem].CmdLineOut m.s.exitCode = 0 // success return gocui.ErrQuit } diff --git a/internal/searchapp/item.go b/internal/searchapp/item.go index 3c86cd5..cf4c1fb 100644 --- a/internal/searchapp/item.go +++ b/internal/searchapp/item.go @@ -31,8 +31,11 @@ type Item struct { sameGitRepo bool exitCode int + // Shown in TUI CmdLineWithColor string CmdLine string + // Unchanged cmdline to paste to command line + CmdLineOut string Score float64 @@ -375,8 +378,8 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo // DISPLAY > cmdline // cmd := "<" + strings.ReplaceAll(record.CmdLine, "\n", ";") + ">" - cmdLine := strings.ReplaceAll(record.CmdLine, "\n", ";") - cmdLineWithColor := strings.ReplaceAll(cmd, "\n", ";") + cmdLine := strings.ReplaceAll(record.CmdLine, "\n", "\\n ") + cmdLineWithColor := strings.ReplaceAll(cmd, "\n", "\\n ") // KEY for deduplication @@ -391,6 +394,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo return Item{ isRaw: true, + CmdLineOut: record.CmdLine, CmdLine: cmdLine, CmdLineWithColor: cmdLineWithColor, Score: score, @@ -443,6 +447,7 @@ func NewItemFromRecordForQuery(record recordint.SearchApp, query Query, debug bo sameGitRepo: sameGitRepo, exitCode: record.ExitCode, + CmdLineOut: record.CmdLine, CmdLine: cmdLine, CmdLineWithColor: cmdLineWithColor, Score: score, @@ -480,6 +485,7 @@ func GetHeader(compactRendering bool) ItemColumns { type RawItem struct { CmdLineWithColor string CmdLine string + CmdLineOut string Score float64