Skip to content

Commit 596dd1e

Browse files
committed
Strip out BELL/ALERT sequence
1 parent 34f7899 commit 596dd1e

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

helpers_windows.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ package termtest
22

33
import (
44
"bytes"
5-
6-
"golang.org/x/sys/windows"
75
)
86

9-
var ERR_ACCESS_DENIED = windows.ERROR_ACCESS_DENIED
10-
117
const UnicodeEscapeRune = '\u001B'
128
const UnicodeBellRune = '\u0007'
139
const UnicodeBackspaceRune = '\u0008' // Note in the docs this is \u007f, but in actual use we're seeing \u0008. Possibly badly documented.
@@ -51,6 +47,11 @@ func cleanPtySnapshot(snapshot []byte, cursorPos int, isPosix bool) ([]byte, int
5147
switch {
5248
// SEQUENCE START
5349

50+
// Delete alert / bell sequence
51+
case !inEscapeSequence && r == '\a':
52+
dropPos(pos)
53+
continue
54+
5455
// Detect start of escape sequence
5556
case !inEscapeSequence && r == UnicodeEscapeRune:
5657
inEscapeSequence = true

helpers_windows_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ func Test_cleanPtySequences(t *testing.T) {
116116
[]byte("foo"),
117117
-1,
118118
},
119+
{
120+
"Alert / bell character",
121+
[]byte("\aP\x1b[?25lython 3.9.5"),
122+
0,
123+
[]byte("Python 3.9.5"),
124+
-1,
125+
},
119126
}
120127
for _, tt := range tests {
121128
t.Run(tt.name, func(t *testing.T) {

termtest_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import (
77
"time"
88

99
gopsutil "github.com/shirou/gopsutil/v3/process"
10+
"golang.org/x/sys/windows"
1011
)
1112

13+
var ERR_ACCESS_DENIED = windows.ERROR_ACCESS_DENIED
14+
1215
func syscallErrorCode(err error) int {
1316
if errv, ok := err.(syscall.Errno); ok {
1417
return int(errv)

0 commit comments

Comments
 (0)