Merge pull request #35 from liamg/modifier-keys

Modifier key support
This commit is contained in:
Liam Galvin 2018-10-23 20:40:07 +01:00 committed by GitHub
commit 9596620042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 232 additions and 200 deletions

View File

@ -1,6 +1,10 @@
package gui package gui
import "github.com/go-gl/glfw/v3.2/glfw" import (
"fmt"
"github.com/go-gl/glfw/v3.2/glfw"
)
// send typed runes straight through to the pty // send typed runes straight through to the pty
func (gui *GUI) char(w *glfw.Window, r rune) { func (gui *GUI) char(w *glfw.Window, r rune) {
@ -22,24 +26,41 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
gui.logger.Debugf("KEY PRESS: key=0x%X scan=0x%X", key, scancode) gui.logger.Debugf("KEY PRESS: key=0x%X scan=0x%X", key, scancode)
switch true { modStr := ""
switch true {
case modsPressed(mods, glfw.ModControl, glfw.ModShift, glfw.ModAlt):
modStr = "8"
case modsPressed(mods, glfw.ModControl, glfw.ModAlt):
modStr = "7"
case modsPressed(mods, glfw.ModControl, glfw.ModShift): case modsPressed(mods, glfw.ModControl, glfw.ModShift):
modStr = "6"
switch key { switch key {
case glfw.KeyV: case glfw.KeyV:
if s, err := gui.window.GetClipboardString(); err == nil { if s, err := gui.window.GetClipboardString(); err == nil {
_ = gui.terminal.Paste([]byte(s)) _ = gui.terminal.Paste([]byte(s))
} }
return
case glfw.KeySemicolon: case glfw.KeySemicolon:
gui.config.Slomo = !gui.config.Slomo gui.config.Slomo = !gui.config.Slomo
return
} }
case modsPressed(mods, glfw.ModControl): case modsPressed(mods, glfw.ModControl):
modStr = "5"
switch key { switch key {
case glfw.KeyC: // ctrl^c case glfw.KeyC: // ctrl^c
gui.logger.Debugf("Sending CTRL^C") gui.logger.Debugf("Sending CTRL^C")
gui.terminal.Write([]byte{0x3}) // send EOT gui.terminal.Write([]byte{0x3}) // send EOT
return
}
case modsPressed(mods, glfw.ModAlt, glfw.ModShift):
modStr = "4"
case modsPressed(mods, glfw.ModAlt):
modStr = "3"
case modsPressed(mods, glfw.ModShift):
modStr = "2"
} }
default: // no mods
switch key { switch key {
case glfw.KeyF1: case glfw.KeyF1:
@ -127,33 +148,29 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
'3', '~', '3', '~',
}) })
case glfw.KeyHome: case glfw.KeyHome:
gui.terminal.Write([]byte{ if modStr == "" {
0x1b, gui.terminal.Write([]byte("\x1b[1~"))
'[', } else {
'1', gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%s~", modStr)))
'~', }
})
case glfw.KeyEnd: case glfw.KeyEnd:
gui.terminal.Write([]byte{ if modStr == "" {
0x1b, gui.terminal.Write([]byte("\x1b[4~"))
'[', } else {
'4', gui.terminal.Write([]byte(fmt.Sprintf("\x1b[4;%s~", modStr)))
'~', }
})
case glfw.KeyPageUp: case glfw.KeyPageUp:
gui.terminal.Write([]byte{ if modStr == "" {
0x1b, gui.terminal.Write([]byte("\x1b[5~"))
'[', } else {
'5', gui.terminal.Write([]byte(fmt.Sprintf("\x1b[5;%s~", modStr)))
'~', }
})
case glfw.KeyPageDown: case glfw.KeyPageDown:
gui.terminal.Write([]byte{ if modStr == "" {
0x1b, gui.terminal.Write([]byte("\x1b[6~"))
'[', } else {
'6', gui.terminal.Write([]byte(fmt.Sprintf("\x1b[6;%s~", modStr)))
'~', }
})
case glfw.KeyEscape: case glfw.KeyEscape:
if gui.terminal.IsApplicationCursorKeysModeEnabled() { if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{ gui.terminal.Write([]byte{
@ -191,6 +208,10 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
case glfw.KeyBackspace: case glfw.KeyBackspace:
gui.terminal.Write([]byte{0x08}) gui.terminal.Write([]byte{0x08})
case glfw.KeyUp: case glfw.KeyUp:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sA", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() { if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{ gui.terminal.Write([]byte{
0x1b, 0x1b,
@ -205,6 +226,11 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
}) })
} }
case glfw.KeyDown: case glfw.KeyDown:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sB", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() { if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{ gui.terminal.Write([]byte{
0x1b, 0x1b,
@ -219,6 +245,10 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
}) })
} }
case glfw.KeyLeft: case glfw.KeyLeft:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sD", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() { if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{ gui.terminal.Write([]byte{
0x1b, 0x1b,
@ -233,6 +263,10 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
}) })
} }
case glfw.KeyRight: case glfw.KeyRight:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sC", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() { if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{ gui.terminal.Write([]byte{
0x1b, 0x1b,
@ -248,8 +282,6 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
} }
} }
}
//gui.logger.Debugf("Key pressed: 0x%X %q", key, string([]byte{byte(key)})) //gui.logger.Debugf("Key pressed: 0x%X %q", key, string([]byte{byte(key)}))
//gui.terminal.Write([]byte{byte(scancode)}) //gui.terminal.Write([]byte{byte(scancode)})
} }