Merge pull request #96 from tjboldt/fix-vi-arrows

Fixes #94 VT100 arrow keys for application mode
This commit is contained in:
Terence Boldt 2022-03-01 08:31:30 -05:00 committed by GitHub
commit 869eb25c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ var escapeSequence string
var operatingSystemSequence bool var operatingSystemSequence bool
var windowTop int var windowTop int
var windowBottom = 23 var windowBottom = 23
var applicationMode = false
func sendCharacter(comm A2Io, b byte) { func sendCharacter(comm A2Io, b byte) {
if b == 0x1b { if b == 0x1b {
@ -63,11 +64,11 @@ func sendCharacter(comm A2Io, b byte) {
switch escapeSequence { switch escapeSequence {
// Set/clear application mode for cursor // Set/clear application mode for cursor
case "^[[?1h": case "^[[?1h":
//applicationMode = true applicationMode = true
escapeSequence = "" escapeSequence = ""
return return
case "^[[?1l": case "^[[?1l":
//applicationMode = false applicationMode = false
comm.WriteByte('T') comm.WriteByte('T')
comm.WriteByte(0x00) comm.WriteByte(0x00)
comm.WriteByte('B') comm.WriteByte('B')
@ -222,17 +223,32 @@ func readCharacter(comm A2Io) (string, error) {
b, err := comm.ReadByte() b, err := comm.ReadByte()
var s = string(b) var s = string(b)
if err == nil { if err == nil {
switch b { if applicationMode {
case 0x0b: // up switch b {
s = "\033[A" case 0x0b: // up
case 0x0a: // down s = "\033OA"
s = "\033[B" case 0x0a: // down
case 0x15: // right s = "\033OB"
s = "\033[C" case 0x15: // right
case 0x08: // left s = "\033OC"
s = "\033[D" case 0x08: // left
case 0x0d: // return s = "\033OD"
s = string(byte(0x0a)) case 0x0d: // return
s = string(byte(0x0a))
}
} else {
switch b {
case 0x0b: // up
s = "\033[A"
case 0x0a: // down
s = "\033[B"
case 0x15: // right
s = "\033[C"
case 0x08: // left
s = "\033[D"
case 0x0d: // return
s = string(byte(0x0a))
}
} }
} }
return s, err return s, err