Skip to content

Commit c8d719f

Browse files
committed
fix: rxvt key handling enhancments
rxvt uses non-ECMA compliant escapes (not valid CSI sequences) for some key sequences, as it uses '$' as a final character in some cases. This adds support for shift modified keys for insert, delete, home, end, pageup, page down, as well as control-shift variants.
1 parent b8ba7dc commit c8d719f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

input.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ var csiAllKeys = map[csiParamMode]keyMap{
204204
{M: 'z', P: 234}: {Key: KeyF11},
205205
{M: 'z', P: 235}: {Key: KeyF12},
206206
{M: 'z', P: 247}: {Key: KeyInsert},
207+
{M: '^', P: 1}: {Key: KeyHome, Mod: ModCtrl},
208+
{M: '^', P: 2}: {Key: KeyInsert, Mod: ModCtrl},
209+
{M: '^', P: 3}: {Key: KeyDelete, Mod: ModCtrl},
210+
{M: '^', P: 4}: {Key: KeyEnd, Mod: ModCtrl},
211+
{M: '^', P: 5}: {Key: KeyPgUp, Mod: ModCtrl},
212+
{M: '^', P: 6}: {Key: KeyPgDn, Mod: ModCtrl},
207213
{M: '^', P: 7}: {Key: KeyHome, Mod: ModCtrl},
208214
{M: '^', P: 8}: {Key: KeyEnd, Mod: ModCtrl},
209215
{M: '^', P: 11}: {Key: KeyF23},
@@ -228,8 +234,19 @@ var csiAllKeys = map[csiParamMode]keyMap{
228234
{M: '^', P: 34}: {Key: KeyF42},
229235
{M: '@', P: 23}: {Key: KeyF43},
230236
{M: '@', P: 24}: {Key: KeyF44},
237+
{M: '@', P: 1}: {Key: KeyHome, Mod: ModShift | ModCtrl},
238+
{M: '@', P: 2}: {Key: KeyInsert, Mod: ModShift | ModCtrl},
239+
{M: '@', P: 3}: {Key: KeyDelete, Mod: ModShift | ModCtrl},
240+
{M: '@', P: 4}: {Key: KeyEnd, Mod: ModShift | ModCtrl},
241+
{M: '@', P: 5}: {Key: KeyPgUp, Mod: ModShift | ModCtrl},
242+
{M: '@', P: 6}: {Key: KeyPgDn, Mod: ModShift | ModCtrl},
243+
{M: '@', P: 7}: {Key: KeyHome, Mod: ModShift | ModCtrl},
244+
{M: '@', P: 8}: {Key: KeyEnd, Mod: ModShift | ModCtrl},
245+
{M: '$', P: 1}: {Key: KeyHome, Mod: ModShift},
231246
{M: '$', P: 2}: {Key: KeyInsert, Mod: ModShift},
232247
{M: '$', P: 3}: {Key: KeyDelete, Mod: ModShift},
248+
{M: '$', P: 5}: {Key: KeyPgUp, Mod: ModShift},
249+
{M: '$', P: 6}: {Key: KeyPgDn, Mod: ModShift},
233250
{M: '$', P: 7}: {Key: KeyHome, Mod: ModShift},
234251
{M: '$', P: 8}: {Key: KeyEnd, Mod: ModShift},
235252
{M: '$', P: 23}: {Key: KeyF21},
@@ -463,10 +480,16 @@ func (ip *inputProcessor) scan() {
463480
}
464481
case inpStateCsi:
465482
// usual case for incoming keys
483+
// NB: rxvt uses terminating '$' which is not a legal CSI terminator,
484+
// for certain shifted key sequences. We special case this, and it's ok
485+
// because no other terminal seems to use this for CSI intermediates from
486+
// the terminal to the host (queries in the other direction can use it.)
466487
if r >= 0x30 && r <= 0x3F { // parameter bytes
467488
ip.csiParams = append(ip.csiParams, byte(r))
468-
} else if r >= 0x20 && r <= 0x2F { // intermediate bytes, rarely used
489+
} else if r >= 0x20 && r <= 0x2F && !(r == '$' && len(ip.csiParams) >= 1) { // intermediate bytes, rarely used
469490
ip.csiInterm = append(ip.csiInterm, byte(r))
491+
} else if r == '$' && len(ip.csiParams) > 0 { // rxvt non-standard
492+
ip.handleCsi(r, ip.csiParams, ip.csiInterm)
470493
} else if r >= 0x40 && r <= 0x7F { // final byte
471494
ip.handleCsi(r, ip.csiParams, ip.csiInterm)
472495
} else {

0 commit comments

Comments
 (0)