2020-06-08 20:52:18 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pexpect_helper import SpawnedProc
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from time import sleep
|
|
|
|
import os
|
|
|
|
|
|
|
|
os.environ["fish_escape_delay_ms"] = "10"
|
|
|
|
SpawnedProc()
|
|
|
|
sp = SpawnedProc()
|
|
|
|
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
|
|
|
|
sp.send,
|
|
|
|
sp.sendline,
|
|
|
|
sp.sleep,
|
|
|
|
sp.expect_prompt,
|
|
|
|
sp.expect_re,
|
|
|
|
sp.expect_str,
|
|
|
|
)
|
|
|
|
expect_prompt()
|
|
|
|
|
2024-01-22 16:16:06 +00:00
|
|
|
sendline("$fish_key_reader --version")
|
|
|
|
expect_re("fish_key_reader, version .*")
|
|
|
|
expect_prompt()
|
|
|
|
|
2021-11-22 16:22:22 +00:00
|
|
|
sendline("exec $fish_key_reader -c -V")
|
2020-06-08 20:52:18 +00:00
|
|
|
|
|
|
|
# Do we get the expected startup prompt?
|
|
|
|
expect_str("Press a key:")
|
|
|
|
|
|
|
|
# Is a single control char echoed correctly?
|
2020-06-17 13:51:10 +00:00
|
|
|
send("\x07")
|
2023-01-27 16:02:02 +00:00
|
|
|
expect_str("char: \\cG\r\nbind \\cG 'do something'\r\n")
|
2020-06-08 20:52:18 +00:00
|
|
|
|
|
|
|
# Is a non-ASCII UTF-8 sequence prefaced by an escape char handled correctly?
|
|
|
|
sleep(0.020)
|
|
|
|
# send "\x1B\xE1\x88\xB4"
|
|
|
|
send("\x1B\u1234")
|
2023-08-26 07:40:53 +00:00
|
|
|
expect_str("char: ሴ\r\nbind \\eሴ 'do something'\r\n")
|
2020-06-08 20:52:18 +00:00
|
|
|
|
|
|
|
# Is a NULL char echoed correctly?
|
|
|
|
sleep(0.020)
|
|
|
|
send("\x00")
|
|
|
|
expect_str("char: \\c@\r\nbind -k nul 'do something'\r\n")
|
|
|
|
|
2024-01-02 16:20:42 +00:00
|
|
|
# Ensure we only name the sequence if we match all of it.
|
|
|
|
# Otherwise we end up calling escape+backspace "backspace"!
|
|
|
|
send("\x1b\x7f")
|
2024-01-07 14:13:34 +00:00
|
|
|
expect_str("char: \\e\r\n")
|
|
|
|
expect_str("char: \\x7F")
|
|
|
|
expect_str("""(aka "del")\r\nbind \\e\\x7F 'do something'\r\n""")
|
2024-01-02 16:20:42 +00:00
|
|
|
|
2024-02-01 20:42:55 +00:00
|
|
|
send("\x1c")
|
|
|
|
expect_str(r"char: \c\ (or \x1c)")
|
|
|
|
expect_str(r"bind \x1c 'do something'")
|
|
|
|
|
2020-06-08 20:52:18 +00:00
|
|
|
# Does it keep running if handed control sequences in the wrong order?
|
|
|
|
send("\x03")
|
|
|
|
sleep(0.010)
|
|
|
|
send("\x04")
|
|
|
|
expect_str("char: \\cD\r\n")
|
|
|
|
|
|
|
|
# Now send a second [ctrl-D]. Does that terminate the process like it should?
|
2020-11-11 18:00:49 +00:00
|
|
|
sleep(0.050)
|
|
|
|
send("\x04\x04")
|
2020-06-08 20:52:18 +00:00
|
|
|
expect_str("char: \\cD\r\n")
|
|
|
|
expect_str("Exiting at your request.\r\n")
|