Add basic fix for #225 by escaping tab characters before rendering

This is a tricky bug to fix because the width of a tab character varies depending on context. This means that when we're trying to build a table and calculating the width of columns for budgeting, we can't actually know the width of a tab without knowing exactly what characters come before it. This is in theory doable, but it leads to some really complex code that I'd rather not adopt.
This commit is contained in:
David Dworken 2024-07-06 19:21:34 -07:00
parent 7451f84ef0
commit c3adc902ad
No known key found for this signature in database
3 changed files with 46 additions and 1 deletions

View File

@ -117,6 +117,7 @@ func TestParam(t *testing.T) {
t.Run("testTui/keybindings", wrapTestForSharding(testTui_keybindings)) t.Run("testTui/keybindings", wrapTestForSharding(testTui_keybindings))
t.Run("testTui/ai", wrapTestForSharding(testTui_ai)) t.Run("testTui/ai", wrapTestForSharding(testTui_ai))
t.Run("testTui/defaultFilter", wrapTestForSharding(testTui_defaultFilter)) t.Run("testTui/defaultFilter", wrapTestForSharding(testTui_defaultFilter))
t.Run("testTui/escaping", wrapTestForSharding(testTui_escaping))
// Assert there are no leaked connections // Assert there are no leaked connections
assertNoLeakedConnections(t) assertNoLeakedConnections(t)
@ -1829,6 +1830,23 @@ func testTui_scroll(t *testing.T) {
assertNoLeakedConnections(t) assertNoLeakedConnections(t)
} }
func testTui_escaping(t *testing.T) {
// Setup
defer testutils.BackupAndRestore(t)()
tester, userSecret, _ := setupTestTui(t, Online)
db := hctx.GetDb(hctx.MakeContext())
e := testutils.MakeFakeHistoryEntry("echo 'a\tb\nc'")
require.NoError(t, db.Create(e).Error)
manuallySubmitHistoryEntry(t, userSecret, e)
// Test that it escapes tab and new line characters
out := captureTerminalOutput(t, tester, []string{
"hishtory SPACE tquery ENTER",
})
out = stripTuiCommandPrefix(t, out)
testutils.CompareGoldens(t, out, "TestTui-Escaping")
}
func testTui_defaultFilter(t *testing.T) { func testTui_defaultFilter(t *testing.T) {
// Setup // Setup
defer testutils.BackupAndRestore(t)() defer testutils.BackupAndRestore(t)()

27
client/testdata/TestTui-Escaping vendored Normal file
View File

@ -0,0 +1,27 @@
Search Query: > ls
┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│────────────────────────────────────────────────────────────────────────────────────────────────────────│
│ localhost /tmp/ Oct 17 2022 21:43:26 PDT 3s 2 "echo 'a\tb\nc'" │
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└────────────────────────────────────────────────────────────────────────────────────────────────────────┘
hiSHtory: Search your shell history • ctrl+h help

View File

@ -520,7 +520,7 @@ func getRows(ctx context.Context, columnNames []string, shellName, defaultFilter
} }
func commandEscaper(cmd string) string { func commandEscaper(cmd string) string {
if !strings.Contains(cmd, "\n") { if !strings.Contains(cmd, "\n") && !strings.Contains(cmd, "\t") {
// No special escaping necessary // No special escaping necessary
return cmd return cmd
} }