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
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/ai", wrapTestForSharding(testTui_ai))
t.Run("testTui/defaultFilter", wrapTestForSharding(testTui_defaultFilter))
t.Run("testTui/escaping", wrapTestForSharding(testTui_escaping))
// Assert there are no leaked connections
assertNoLeakedConnections(t)
@ -1829,6 +1830,23 @@ func testTui_scroll(t *testing.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) {
// Setup
defer testutils.BackupAndRestore(t)()