diff --git a/client/client_test.go b/client/client_test.go index b2dda3f..c250f14 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2047,12 +2047,37 @@ func testControlR(t *testing.T, tester shellTester, shellName string, onlineStat testutils.Check(t, err) // And check that the control-r bindings work again - out = captureTerminalOutputWithShellName(t, tester, "fish", []string{"C-R", "-pipefail SPACE -exit_code:0"}) - if !strings.Contains(out, "\n\n\n") { - t.Fatalf("failed to find separator in %#v", out) + out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "-pipefail SPACE -exit_code:0"}) + if strings.Contains(out, "\n\n\n") { + out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1]) } - out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1]) compareGoldens(t, out, "testControlR-Final") + + // Record a multi-line command + tester.RunInteractiveShell(t, ` hishtory enable`) + tester.RunInteractiveShell(t, `ls \ +-Slah \ +/`) + tester.RunInteractiveShell(t, ` hishtory disable`) + + // Check that we display it in the table reasonably + out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Slah"}) + if strings.Contains(out, "\n\n\n") { + out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1]) + } + compareGoldens(t, out, "testControlR-DisplayMultiline-"+shellName) + + // Check that we can select it correctly + out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "Slah", "Enter"}) + if strings.Contains(out, "\n\n\n") { + out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1]) + } + if !strings.Contains(out, "-Slah") { + t.Fatalf("out has unexpected output missing the selected row: \n%s", out) + } + if !testutils.IsGithubAction() { + compareGoldens(t, out, "testControlR-SelectMultiline-"+shellName) + } } func testCustomColumns(t *testing.T, tester shellTester) { diff --git a/client/lib/config.fish b/client/lib/config.fish index b7e0b50..b391809 100644 --- a/client/lib/config.fish +++ b/client/lib/config.fish @@ -26,7 +26,7 @@ function __hishtory_on_control_r set -l res $status commandline -f repaint if [ -s $tmp ] - commandline -r (cat $tmp) + commandline -r -- (cat $tmp) end rm -f $tmp end diff --git a/client/lib/config.sh b/client/lib/config.sh index abc69f8..8e564ca 100644 --- a/client/lib/config.sh +++ b/client/lib/config.sh @@ -35,7 +35,7 @@ PROMPT_COMMAND="__hishtory_postcommand; $PROMPT_COMMAND" export HISTTIMEFORMAT=$HISTTIMEFORMAT __history_control_r() { - READLINE_LINE=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery "$READLINE_LINE" | tr -d '\n') + READLINE_LINE=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery "$READLINE_LINE") READLINE_POINT=0x7FFFFFFF } diff --git a/client/lib/config.zsh b/client/lib/config.zsh index 895b847..84be165 100644 --- a/client/lib/config.zsh +++ b/client/lib/config.zsh @@ -24,7 +24,7 @@ function _hishtory_precmd() { } _hishtory_widget() { - BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER | tr -d '\n') + BUFFER=$(HISHTORY_TERM_INTEGRATION=1 hishtory tquery $BUFFER) CURSOR=${#BUFFER} zle reset-prompt } diff --git a/client/lib/goldens/testControlR-DisplayMultiline-bash b/client/lib/goldens/testControlR-DisplayMultiline-bash new file mode 100644 index 0000000..0346dec --- /dev/null +++ b/client/lib/goldens/testControlR-DisplayMultiline-bash @@ -0,0 +1,26 @@ +Search Query: > Slah + +┌─────────────────────────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│─────────────────────────────────────────────────────────────────────────────│ +│ ghaction-runner-hostname 0 ls -Slah / foo │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-DisplayMultiline-fish b/client/lib/goldens/testControlR-DisplayMultiline-fish new file mode 100644 index 0000000..0346dec --- /dev/null +++ b/client/lib/goldens/testControlR-DisplayMultiline-fish @@ -0,0 +1,26 @@ +Search Query: > Slah + +┌─────────────────────────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│─────────────────────────────────────────────────────────────────────────────│ +│ ghaction-runner-hostname 0 ls -Slah / foo │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-DisplayMultiline-zsh b/client/lib/goldens/testControlR-DisplayMultiline-zsh new file mode 100644 index 0000000..c31a72e --- /dev/null +++ b/client/lib/goldens/testControlR-DisplayMultiline-zsh @@ -0,0 +1,26 @@ +Search Query: > Slah + +┌─────────────────────────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│─────────────────────────────────────────────────────────────────────────────│ +│ ghaction-runner-hostname 0 ls \\n-Slah \\n/ foo │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-SelectMultiline-bash b/client/lib/goldens/testControlR-SelectMultiline-bash new file mode 100644 index 0000000..0dd1add --- /dev/null +++ b/client/lib/goldens/testControlR-SelectMultiline-bash @@ -0,0 +1,2 @@ +bash-5.2$ source /Users/david/.bashrc +bash-5.2$ ls -Slah / \ No newline at end of file diff --git a/client/lib/goldens/testControlR-SelectMultiline-fish b/client/lib/goldens/testControlR-SelectMultiline-fish new file mode 100644 index 0000000..cc996b7 --- /dev/null +++ b/client/lib/goldens/testControlR-SelectMultiline-fish @@ -0,0 +1,3 @@ +Welcome to fish, the friendly interactive shell +Type help for instructions on how to use fish +david@Davids-MacBook-Air ~/c/hishtory (master)> ls -Slah /AppleInternal/ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-SelectMultiline-zsh b/client/lib/goldens/testControlR-SelectMultiline-zsh new file mode 100644 index 0000000..9752a55 --- /dev/null +++ b/client/lib/goldens/testControlR-SelectMultiline-zsh @@ -0,0 +1,3 @@ +david@Davids-MacBook-Air hishtory % ls \ +-Slah \ +/ \ No newline at end of file diff --git a/client/lib/tui.go b/client/lib/tui.go index dd39e99..c79762b 100644 --- a/client/lib/tui.go +++ b/client/lib/tui.go @@ -228,7 +228,7 @@ func getRows(ctx *context.Context, columnNames []string, query string, numEntrie if strings.TrimSpace(entry.Command) == strings.TrimSpace(lastCommand) && config.FilterDuplicateCommands { continue } - entry.Command = strings.ReplaceAll(entry.Command, "\n", "; ") + entry.Command = strings.ReplaceAll(entry.Command, "\n", "\\n") row, err := buildTableRow(ctx, columnNames, *entry) if err != nil { return nil, 0, fmt.Errorf("failed to build row for entry=%#v: %v", entry, err) @@ -454,6 +454,6 @@ func TuiQuery(ctx *context.Context, initialQuery string) error { // Print out the initialQuery instead so that we don't clear the terminal selectedRow = initialQuery } - fmt.Printf("%s\n", selectedRow) + fmt.Printf("%s\n", strings.ReplaceAll(selectedRow, "\\n", "\n")) return nil }