浏览代码

ssh/terminal: support ^N and ^P

This makes it possible to navigate the history without leaving
the home row on the keyboard.

Change-Id: Id24c43f8eb6090520ab37bf8126264901b70c489
Reviewed-on: https://go-review.googlesource.com/c/33618
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Michal Bohuslávek 9 年之前
父节点
当前提交
c7b33c32a3
共有 2 个文件被更改,包括 10 次插入0 次删除
  1. 4 0
      ssh/terminal/terminal.go
  2. 6 0
      ssh/terminal/terminal_test.go

+ 4 - 0
ssh/terminal/terminal.go

@@ -159,6 +159,10 @@ func bytesToKey(b []byte, pasteActive bool) (rune, []byte) {
 			return keyClearScreen, b[1:]
 		case 23: // ^W
 			return keyDeleteWord, b[1:]
+		case 14: // ^N
+			return keyDown, b[1:]
+		case 16: // ^P
+			return keyUp, b[1:]
 		}
 	}
 

+ 6 - 0
ssh/terminal/terminal_test.go

@@ -91,6 +91,12 @@ var keyPressTests = []struct {
 	{
 		in: "\x1b[B\r", // down
 	},
+	{
+		in: "\016\r", // ^P
+	},
+	{
+		in: "\014\r", // ^N
+	},
 	{
 		in:   "line\x1b[A\x1b[B\r", // up then down
 		line: "line",