Merge pull request from michalpristas/add-delete-home-end-support

Add delete home end support
This commit is contained in:
Chzyer 2015-10-28 08:55:01 +08:00
commit ffee92f4b7
2 changed files with 12 additions and 2 deletions

View File

@ -107,7 +107,7 @@ func (t *Terminal) ioloop() {
r = escapeKey(r)
} else if isEscapeEx {
isEscapeEx = false
r = escapeExKey(r)
r = escapeExKey(r, buf)
}
expectNextChar = true

View File

@ -1,6 +1,7 @@
package readline
import (
"bufio"
"strconv"
"syscall"
@ -38,8 +39,13 @@ func IsPrintable(key rune) bool {
}
// translate Esc[X
func escapeExKey(r rune) rune {
func escapeExKey(r rune, reader *bufio.Reader) rune {
switch r {
case 51:
r = CharDelete
if d, _, err := reader.ReadRune(); reader != nil && (err != nil || d != 126) {
reader.UnreadRune()
}
case 'D':
r = CharBackward
case 'C':
@ -48,6 +54,10 @@ func escapeExKey(r rune) rune {
r = CharPrev
case 'B':
r = CharNext
case 'H':
r = CharLineStart
case 'F':
r = CharLineEnd
}
return r
}