1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-24 13:48:51 +08:00

fixes #109 Support both meta and alt + arrow keys

This commit is contained in:
Zachary Yedidia 2016-04-30 10:32:37 -04:00 committed by Garrett D'Amore
parent 9059a787e5
commit f722733809
5 changed files with 103 additions and 43 deletions

View File

@ -1 +1,2 @@
Garrett D'Amore <garrett@damore.org>
Zachary Yedidia <zyedidia@gmail.com>

View File

@ -896,16 +896,22 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
AddTerminfo(&Terminfo{
Name: "gnome-256color",
@ -1019,16 +1025,22 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
AddTerminfo(&Terminfo{
Name: "hpterm",
@ -2598,16 +2610,22 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
AddTerminfo(&Terminfo{
Name: "xnuppc",
@ -2744,16 +2762,22 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
AddTerminfo(&Terminfo{
Name: "xterm-256color",
@ -2866,16 +2890,22 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
AddTerminfo(&Terminfo{
Name: "xterm-truecolor",
@ -2990,15 +3020,21 @@ func init() {
KeyCtrlRight: "\x1b[1;5C",
KeyCtrlUp: "\x1b[1;5A",
KeyCtrlDown: "\x1b[1;5B",
KeyAltLeft: "\x1b[1;9D",
KeyAltRight: "\x1b[1;9C",
KeyAltUp: "\x1b[1;9A",
KeyAltDown: "\x1b[1;9B",
KeyAltLeft: "\x1b[1;3D",
KeyAltRight: "\x1b[1;3C",
KeyAltUp: "\x1b[1;3A",
KeyAltDown: "\x1b[1;3B",
KeyMetaLeft: "\x1b[1;9D",
KeyMetaRight: "\x1b[1;9C",
KeyMetaUp: "\x1b[1;9A",
KeyMetaDown: "\x1b[1;9B",
KeyShfHome: "\x1b[1;2H",
KeyShfEnd: "\x1b[1;2F",
KeyCtrlHome: "\x1b[1;5H",
KeyCtrlEnd: "\x1b[1;5F",
KeyAltHome: "\x1b[1;9H",
KeyAltEnd: "\x1b[1;9F",
KeyAltHome: "\x1b[1;3H",
KeyAltEnd: "\x1b[1;3F",
KeyMetaHome: "\x1b[1;9H",
KeyMetaEnd: "\x1b[1;9F",
})
}

View File

@ -1,6 +1,6 @@
// +build ignore
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -246,10 +246,14 @@ func getinfo(name string) (*tcell.Terminfo, error) {
if t.KeyShfRight == "\x1b[1;2C" && t.KeyShfLeft == "\x1b[1;2D" {
t.KeyShfUp = "\x1b[1;2A"
t.KeyShfDown = "\x1b[1;2B"
t.KeyAltUp = "\x1b[1;9A"
t.KeyAltDown = "\x1b[1;9B"
t.KeyAltRight = "\x1b[1;9C"
t.KeyAltLeft = "\x1b[1;9D"
t.KeyMetaUp = "\x1b[1;9A"
t.KeyMetaDown = "\x1b[1;9B"
t.KeyMetaRight = "\x1b[1;9C"
t.KeyMetaLeft = "\x1b[1;9D"
t.KeyAltUp = "\x1b[1;3A"
t.KeyAltDown = "\x1b[1;3B"
t.KeyAltRight = "\x1b[1;3C"
t.KeyAltLeft = "\x1b[1;3D"
t.KeyCtrlUp = "\x1b[1;5A"
t.KeyCtrlDown = "\x1b[1;5B"
t.KeyCtrlRight = "\x1b[1;5C"
@ -496,6 +500,10 @@ func dotGoInfo(w io.Writer, t *tcell.Terminfo) {
dotGoAddStr(w, "KeyCtrlRight", t.KeyCtrlRight)
dotGoAddStr(w, "KeyCtrlUp", t.KeyCtrlUp)
dotGoAddStr(w, "KeyCtrlDown", t.KeyCtrlDown)
dotGoAddStr(w, "KeyMetaLeft", t.KeyMetaLeft)
dotGoAddStr(w, "KeyMetaRight", t.KeyMetaRight)
dotGoAddStr(w, "KeyMetaUp", t.KeyMetaUp)
dotGoAddStr(w, "KeyMetaDown", t.KeyMetaDown)
dotGoAddStr(w, "KeyAltLeft", t.KeyAltLeft)
dotGoAddStr(w, "KeyAltRight", t.KeyAltRight)
dotGoAddStr(w, "KeyAltUp", t.KeyAltUp)
@ -504,6 +512,8 @@ func dotGoInfo(w io.Writer, t *tcell.Terminfo) {
dotGoAddStr(w, "KeyShfEnd", t.KeyShfEnd)
dotGoAddStr(w, "KeyCtrlHome", t.KeyCtrlHome)
dotGoAddStr(w, "KeyCtrlEnd", t.KeyCtrlEnd)
dotGoAddStr(w, "KeyMetaHome", t.KeyMetaHome)
dotGoAddStr(w, "KeyMetaEnd", t.KeyMetaEnd)
dotGoAddStr(w, "KeyAltHome", t.KeyAltHome)
dotGoAddStr(w, "KeyAltEnd", t.KeyAltEnd)
fmt.Fprintln(w, " })")

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors
// Copyright 2016 The TCell Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License.
@ -156,17 +156,23 @@ type Terminfo struct {
SetFgRGB string `json:"_setfrgb,omitempty"` // setfrgb
SetBgRGB string `json:"_setbrgb,omitempty"` // setbrgb
KeyShfUp string `json:"_kscu1,omitempty"` // shift-up
KeyShfDown string `json:"_kscud1,omitempty"` // shift-left
KeyShfDown string `json:"_kscud1,omitempty"` // shift-down
KeyCtrlUp string `json:"_kccu1,omitempty"` // ctrl-up
KeyCtrlDown string `json:"_kccud1,omitempty"` // ctrl-left
KeyCtrlRight string `json:"_kccuf1,omitempty"` // ctrl-right
KeyCtrlLeft string `json:"_kccub1,omitempty"` // ctrl-left
KeyMetaUp string `json:"_kmcu1,omitempty"` // meta-up
KeyMetaDown string `json:"_kmcud1,omitempty"` // meta-left
KeyMetaRight string `json:"_kmcuf1,omitempty"` // meta-right
KeyMetaLeft string `json:"_kmcub1,omitempty"` // meta-left
KeyAltUp string `json:"_kacu1,omitempty"` // alt-up
KeyAltDown string `json:"_kacud1,omitempty"` // alt-left
KeyAltRight string `json:"_kacuf1,omitempty"` // alt-right
KeyAltLeft string `json:"_kacub1,omitempty"` // alt-left
KeyCtrlHome string `json:"_kchome,omitempty"`
KeyCtrlEnd string `json:"_kcend,omitempty"`
KeyMetaHome string `json:"_kmhome,omitempty"`
KeyMetaEnd string `json:"_kmend,omitempty"`
KeyAltHome string `json:"_kahome,omitempty"`
KeyAltEnd string `json:"_kaend,omitempty"`
}

View File

@ -287,6 +287,13 @@ func (t *tScreen) prepareKeys() {
t.prepareKeyMod(KeyHome, ModAlt, ti.KeyAltHome)
t.prepareKeyMod(KeyEnd, ModAlt, ti.KeyAltEnd)
t.prepareKeyMod(KeyRight, ModMeta, ti.KeyMetaRight)
t.prepareKeyMod(KeyLeft, ModMeta, ti.KeyMetaLeft)
t.prepareKeyMod(KeyUp, ModMeta, ti.KeyMetaUp)
t.prepareKeyMod(KeyDown, ModMeta, ti.KeyMetaDown)
t.prepareKeyMod(KeyHome, ModMeta, ti.KeyMetaHome)
t.prepareKeyMod(KeyEnd, ModMeta, ti.KeyMetaEnd)
// Sadly, xterm handling of keycodes is somewhat erratic. In
// particular, different codes are sent depending on application
// mode is in use or not, and the entries for many of these are