Add workaround for #221 to strip out escape codes from kitty in screen

This commit is contained in:
David Dworken 2024-08-25 18:56:53 -07:00
parent 1d27c15315
commit 6fd624f32c
No known key found for this signature in database
4 changed files with 61 additions and 0 deletions

View File

@ -3290,4 +3290,21 @@ func TestConfigLogLevel(t *testing.T) {
require.Equal(t, "info\n", out)
}
func TestSanitizeEscapeCodes(t *testing.T) {
markTestForSharding(t, 17)
defer testutils.BackupAndRestore(t)()
tester := zshTester{}
installHishtory(t, tester, "")
// Input the escape code sequence
out := captureTerminalOutput(t, tester, []string{
"hishtory SPACE tquery ENTER",
"'11;rgb:1c1c/1c1c/1c1c'",
"SPACE",
})
// Compare the output with the golden file
testutils.CompareGoldens(t, out, "TestSanitizeEscapeCodes-Output")
}
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed

View File

@ -0,0 +1,31 @@
david@ghaction-runner-hostname hishtory % hishtory tquery
Search Query: >
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│───────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│ ghaction-runner-hostname ~/code/hishtory Aug 25 2024 18:52:40 PDT N/A 0 hishtory tquery │
│ ghaction-runner-hostname ~/code/hishtory Aug 25 2024 18:52:39 PDT 45ms 0 set -eo pipefail │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
hiSHtory: Search your shell history • ctrl+h help

View File

@ -225,7 +225,13 @@ func runQueryAndUpdateTable(m model, forceUpdateTable, maintainCursor bool) tea.
return nil
}
func sanitizeEscapeCodes(input string) string {
re := regexp.MustCompile(`\d\d;rgb:[0-9a-f]{4}/[0-9a-f]{4}/[0-9a-f]{4}`)
return re.ReplaceAllString(input, "")
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.queryInput.SetValue(sanitizeEscapeCodes(m.queryInput.Value()))
switch msg := msg.(type) {
case tea.KeyMsg:
switch {

View File

@ -14,3 +14,10 @@ func TestCalculateWordBoundaries(t *testing.T) {
require.Equal(t, []int{0, 3, 10, 16}, calculateWordBoundaries("foo-- -bar - baz"))
require.Equal(t, []int{0, 3}, calculateWordBoundaries("foo "))
}
func TestSanitizeEscapeCodes(t *testing.T) {
require.Equal(t, "foo", sanitizeEscapeCodes("foo"))
require.Equal(t, "foo\x1b[31mbar", sanitizeEscapeCodes("foo\x1b[31mbar"))
require.Equal(t, "", sanitizeEscapeCodes("11;rgb:1c1c/1c1c/1c1c"))
require.Equal(t, "foo bar", sanitizeEscapeCodes("foo 11;rgb:1c1c/1c1c/1c1c bar"))
}