Skip to content

Commit d5e2e32

Browse files
committed
runtest: respond to cursor query escape sequence
If the program uses ncurses it may send a cursor query escape sequence and wait/hang until a response is received. Detect this and respond with a cursor position (1,1) escape code.
1 parent 0da3a26 commit d5e2e32

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

runtest.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ def read_to_prompt(self, prompts, timeout):
123123
if self.stdout in outs:
124124
new_data = self.stdout.read(1)
125125
new_data = new_data.decode("latin1") if IS_PY_3 else new_data
126-
#print("new_data: '%s'" % new_data)
126+
#print("new_data: %s" % repr(new_data))
127127
debug(new_data)
128128
# Perform newline cleanup
129129
self.buf += new_data.replace("\r", "")
130+
if self.buf.endswith('\x1b[6n'):
131+
log("Handling cursor query")
132+
self.stdin.write(b"\x1b[1;1R")
133+
self.buf = ""
134+
continue
130135
for prompt in prompts:
131136
regexp = re.compile(prompt)
132137
match = regexp.search(self.buf)
@@ -142,7 +147,9 @@ def writeline(self, str):
142147
def _to_bytes(s):
143148
return bytes(s, "latin1") if IS_PY_3 else s
144149

145-
self.stdin.write(_to_bytes(str.replace('\r', '\x16\r') + self.line_break))
150+
data = _to_bytes(str.replace('\r', '\x16\r') + self.line_break)
151+
#print("write: %s" % repr(data))
152+
self.stdin.write(data)
146153

147154
def cleanup(self):
148155
#print "cleaning up"

0 commit comments

Comments
 (0)