ssh/terminal: handle ctrl+C, ctrl+F, ctrl+B

ctrl+C: terminate readline, which may result in application termination.
ctrl+F: keyRight
ctrl+B: keyLeft

Update golang/go#27147

Change-Id: If319ef79708b98c030cbce102400a785d15137f8
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/228223
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hana (Hyang-Ah) Kim
2020-04-14 15:58:20 +00:00
committed by Hyang-Ah Hana Kim
parent 056763e48d
commit 4f8f47aa79
2 changed files with 26 additions and 0 deletions
+18
View File
@@ -81,6 +81,14 @@ var keyPressTests = []struct {
in: "a\x1b[Db\r", // left
line: "ba",
},
{
in: "a\006b\r", // ^F
line: "ab",
},
{
in: "a\002b\r", // ^B
line: "ba",
},
{
in: "a\177b\r", // backspace
line: "b",
@@ -208,6 +216,16 @@ var keyPressTests = []struct {
line: "a",
err: ErrPasteIndicator,
},
{
// Ctrl-C terminates readline
in: "\003",
err: io.EOF,
},
{
// Ctrl-C at the end of line also terminates readline
in: "a\003\r",
err: io.EOF,
},
}
func TestKeyPresses(t *testing.T) {