mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 20:07:52 +02:00
Add workaround for #221 to strip out escape codes from kitty in screen
This commit is contained in:
parent
1d27c15315
commit
6fd624f32c
@ -3290,4 +3290,21 @@ func TestConfigLogLevel(t *testing.T) {
|
|||||||
require.Equal(t, "info\n", out)
|
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
|
// TODO: somehow test/confirm that hishtory works even if only bash/only zsh is installed
|
||||||
|
31
client/testdata/TestSanitizeEscapeCodes-Output
vendored
Normal file
31
client/testdata/TestSanitizeEscapeCodes-Output
vendored
Normal 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
|
@ -225,7 +225,13 @@ func runQueryAndUpdateTable(m model, forceUpdateTable, maintainCursor bool) tea.
|
|||||||
return nil
|
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) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
m.queryInput.SetValue(sanitizeEscapeCodes(m.queryInput.Value()))
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch {
|
switch {
|
||||||
|
@ -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, 10, 16}, calculateWordBoundaries("foo-- -bar - baz"))
|
||||||
require.Equal(t, []int{0, 3}, calculateWordBoundaries("foo "))
|
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"))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user