2020-06-09 04:52:18 +08: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-23 00:16:06 +08:00
|
|
|
sendline("$fish_key_reader --version")
|
|
|
|
expect_re("fish_key_reader, version .*")
|
|
|
|
expect_prompt()
|
|
|
|
|
2021-11-23 00:22:22 +08:00
|
|
|
sendline("exec $fish_key_reader -c -V")
|
2020-06-09 04:52:18 +08:00
|
|
|
|
|
|
|
# Do we get the expected startup prompt?
|
|
|
|
expect_str("Press a key:")
|
|
|
|
|
|
|
|
# Is a single control char echoed correctly?
|
2020-06-17 21:51:10 +08:00
|
|
|
send("\x07")
|
2024-08-11 20:49:08 +08:00
|
|
|
expect_str("# decoded from: \\x07\r\n")
|
2024-03-30 23:10:12 +08:00
|
|
|
expect_str("bind ctrl-g 'do something'\r\n")
|
2020-06-09 04:52:18 +08:00
|
|
|
|
|
|
|
# Is a non-ASCII UTF-8 sequence prefaced by an escape char handled correctly?
|
|
|
|
sleep(0.020)
|
2024-03-30 23:10:12 +08:00
|
|
|
send("\x1B")
|
2024-08-11 20:49:08 +08:00
|
|
|
expect_str("# decoded from: \\e\r\n")
|
2024-03-30 23:10:12 +08:00
|
|
|
expect_str("bind escape 'do something'\r\n")
|
2024-08-13 22:01:00 +08:00
|
|
|
send("ö")
|
|
|
|
expect_str("# decoded from: ö\r\n")
|
|
|
|
expect_str("bind ö 'do something'\r\n")
|
2024-03-30 23:10:12 +08:00
|
|
|
send("\u1234")
|
|
|
|
expect_str("bind ሴ 'do something'\r\n")
|
2020-06-09 04:52:18 +08:00
|
|
|
|
|
|
|
# Is a NULL char echoed correctly?
|
|
|
|
sleep(0.020)
|
|
|
|
send("\x00")
|
2024-03-30 23:10:12 +08:00
|
|
|
expect_str("bind ctrl-space 'do something'\r\n")
|
2020-06-09 04:52:18 +08:00
|
|
|
|
2024-01-03 00:20:42 +08:00
|
|
|
send("\x1b\x7f")
|
2024-08-11 20:49:08 +08:00
|
|
|
expect_str("# decoded from: \\e\\x7f\r\n")
|
2024-03-30 23:10:12 +08:00
|
|
|
expect_str("bind alt-backspace 'do something'\r\n")
|
2024-01-03 00:20:42 +08:00
|
|
|
|
2024-02-02 04:42:55 +08:00
|
|
|
send("\x1c")
|
2024-03-30 23:10:12 +08:00
|
|
|
expect_str(r"bind ctrl-\\ 'do something'")
|
2024-02-02 04:42:55 +08:00
|
|
|
|
2020-06-09 04:52:18 +08:00
|
|
|
# Does it keep running if handed control sequences in the wrong order?
|
|
|
|
send("\x03")
|
|
|
|
sleep(0.010)
|
|
|
|
send("\x04")
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
# Now send a second ctrl-d. Does that terminate the process like it should?
|
2020-11-12 02:00:49 +08:00
|
|
|
sleep(0.050)
|
|
|
|
send("\x04\x04")
|
2020-06-09 04:52:18 +08:00
|
|
|
expect_str("Exiting at your request.\r\n")
|