mirror of
https://github.com/ddworken/hishtory.git
synced 2024-11-22 16:24:00 +01:00
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:
parent
7451f84ef0
commit
c3adc902ad
@ -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)()
|
||||
|
27
client/testdata/TestTui-Escaping
vendored
Normal file
27
client/testdata/TestTui-Escaping
vendored
Normal 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
|
@ -520,7 +520,7 @@ func getRows(ctx context.Context, columnNames []string, shellName, defaultFilter
|
||||
}
|
||||
|
||||
func commandEscaper(cmd string) string {
|
||||
if !strings.Contains(cmd, "\n") {
|
||||
if !strings.Contains(cmd, "\n") && !strings.Contains(cmd, "\t") {
|
||||
// No special escaping necessary
|
||||
return cmd
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user