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
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
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)
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):
modStr = "6"
switch key {
case glfw.KeyV:
if s, err := gui.window.GetClipboardString(); err == nil {
_ = gui.terminal.Paste([]byte(s))
}
return
case glfw.KeySemicolon:
gui.config.Slomo = !gui.config.Slomo
return
}
case modsPressed(mods, glfw.ModControl):
modStr = "5"
switch key {
case glfw.KeyC: // ctrl^c
gui.logger.Debugf("Sending CTRL^C")
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 {
case glfw.KeyF1:
@ -127,33 +148,29 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
'3', '~',
})
case glfw.KeyHome:
gui.terminal.Write([]byte{
0x1b,
'[',
'1',
'~',
})
if modStr == "" {
gui.terminal.Write([]byte("\x1b[1~"))
} else {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%s~", modStr)))
}
case glfw.KeyEnd:
gui.terminal.Write([]byte{
0x1b,
'[',
'4',
'~',
})
if modStr == "" {
gui.terminal.Write([]byte("\x1b[4~"))
} else {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[4;%s~", modStr)))
}
case glfw.KeyPageUp:
gui.terminal.Write([]byte{
0x1b,
'[',
'5',
'~',
})
if modStr == "" {
gui.terminal.Write([]byte("\x1b[5~"))
} else {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[5;%s~", modStr)))
}
case glfw.KeyPageDown:
gui.terminal.Write([]byte{
0x1b,
'[',
'6',
'~',
})
if modStr == "" {
gui.terminal.Write([]byte("\x1b[6~"))
} else {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[6;%s~", modStr)))
}
case glfw.KeyEscape:
if gui.terminal.IsApplicationCursorKeysModeEnabled() {
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:
gui.terminal.Write([]byte{0x08})
case glfw.KeyUp:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sA", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{
0x1b,
@ -205,6 +226,11 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
})
}
case glfw.KeyDown:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sB", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{
0x1b,
@ -219,6 +245,10 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
})
}
case glfw.KeyLeft:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sD", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{
0x1b,
@ -233,6 +263,10 @@ func (gui *GUI) key(w *glfw.Window, key glfw.Key, scancode int, action glfw.Acti
})
}
case glfw.KeyRight:
if modStr != "" {
gui.terminal.Write([]byte(fmt.Sprintf("\x1b[1;%sC", modStr)))
}
if gui.terminal.IsApplicationCursorKeysModeEnabled() {
gui.terminal.Write([]byte{
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.terminal.Write([]byte{byte(scancode)})
}