Skip to content

Commit cbb8618

Browse files
committed
feat: enable XTerm modifyOtherKeys protocol
This gives better key reporting for XTerm and strict clones that implement the modifyOtherKeys (CSI-27-~) protocol.
1 parent c319271 commit cbb8618

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

input.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,23 @@ func (ip *inputProcessor) handleCsi(mode rune, params []byte, intermediate []byt
805805
case '_':
806806
if len(intermediate) == 0 && len(P) > 0 {
807807
ip.handleWinKey(P)
808+
return
809+
}
810+
case '~':
811+
if len(intermediate) == 0 && len(P) >= 2 {
812+
mod := calcModifier(P[1])
813+
if ks, ok := csiAllKeys[csiParamMode{M: mode, P: P0}]; ok {
814+
ip.post(NewEventKey(ks.Key, 0, mod))
815+
return
816+
}
817+
if P0 == 27 && len(P) > 2 {
818+
if P[2] < ' ' || P[2] == 0x7F {
819+
ip.post(NewEventKey(Key(P[2]), 0, mod))
820+
} else {
821+
ip.post(NewEventKey(KeyRune, rune(P[2]), mod))
822+
}
823+
return
824+
}
808825
}
809826
}
810827

@@ -824,7 +841,6 @@ func (ip *inputProcessor) handleCsi(mode rune, params []byte, intermediate []byt
824841
ip.post(NewEventKey(k, 0, calcModifier(P[1])))
825842
return
826843
}
827-
828844
// if we got here we just swallow the unknown sequence
829845
}
830846

tscreen.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"io"
2525
"maps"
2626
"os"
27-
"runtime"
2827
"strconv"
2928
"strings"
3029
"sync"
@@ -320,13 +319,12 @@ func (t *tScreen) prepareExtendedOSC() {
320319
}
321320

322321
if t.enableCsiU == "" && t.ti.XTermLike {
323-
if runtime.GOOS == "windows" {
324-
t.enableCsiU = "\x1b[?9001h"
325-
t.disableCsiU = "\x1b[?9001l"
326-
} else {
327-
t.enableCsiU = "\x1b[>1u"
328-
t.disableCsiU = "\x1b[<u"
329-
}
322+
// three advanced keyboard protocols:
323+
// - xterm modifyOtherKeys (uses CSI 27 ~ )
324+
// - kitty csi-u (uses CSI u)
325+
// - win32-input-mode (uses CSI _)
326+
t.enableCsiU = "\x1b[>4;2m" + "\x1b[>1u" + "\x1b[9001h"
327+
t.disableCsiU = "\x1b[9001l" + "\x1b[<u" + "\x1b[>4;0m"
330328
}
331329
}
332330

0 commit comments

Comments
 (0)