@@ -584,7 +584,6 @@ func (ip *inputParser) scan() {
584584 ip .post (NewEventKey (KeyEscape , "" , ModNone ))
585585 } else if ec := ip .escChar ; ec != 0 {
586586 ip .post (NewEventKey (KeyRune , string (ec ), ModAlt ))
587- } else {
588587 }
589588 // if we take too long between bytes, reset the state machine.
590589 ip .state = istInit
@@ -732,16 +731,21 @@ func (ip *inputParser) handleWinKey(P []int) {
732731 // key up event ignore ignore
733732 return
734733 }
735- if P [0 ] == 0 && P [2 ] == 27 && ip .nested == nil {
736- ip .nested = & inputParser {
737- evch : ip .evch ,
738- rows : ip .rows ,
739- cols : ip .cols ,
740- }
741- }
742734
743- if ip .nested != nil && P [2 ] > 0 && P [2 ] < 0x80 { // only ASCII in win32-input-mode
744- ip .nested .ScanUTF8 ([]byte {byte (P [2 ])})
735+ // these terminals never send ambiguous escapes
736+ ip .escaped = false
737+
738+ if P [0 ] == 0 && P [1 ] == 0 && P [2 ] > 0 && P [2 ] < 0x80 { // only ASCII in win32-input-mode
739+ if ip .nested == nil {
740+ ip .nested = & inputParser {
741+ evch : ip .evch ,
742+ rows : ip .rows ,
743+ cols : ip .cols ,
744+ }
745+ }
746+ if P [2 ] > 0 {
747+ ip .nested .ScanUTF8 ([]byte {byte (P [2 ])})
748+ }
745749 return
746750 }
747751
@@ -814,6 +818,8 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte)
814818 if n , e := strconv .ParseInt (parts [i ], 10 , 32 ); e == nil {
815819 P = append (P , int (n ))
816820 }
821+ } else {
822+ P = append (P , 0 )
817823 }
818824 }
819825 }
@@ -827,6 +833,7 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte)
827833 case 'm' , 'M' : // mouse event, we only do SGR tracking
828834 ip .handleMouse (mode , P )
829835 }
836+ return
830837 }
831838
832839 switch mode {
@@ -841,8 +848,8 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte)
841848 ip .state = istLnx
842849 return
843850 case 'u' :
844- // CSI-u kitty keyboard protocol
845- if len (P ) > 0 && ! hasLT {
851+ // CSI-u kitty keyboard protocol, is unambiguous
852+ if len (P ) > 0 {
846853 mod := ModNone
847854 key := KeyRune
848855 chr := rune (0 )
@@ -874,7 +881,7 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte)
874881 return
875882 }
876883 case '~' :
877- if len (P ) >= 2 && ! hasLT {
884+ if len (P ) >= 2 {
878885 mod := calcModifier (P [1 ])
879886 if ks , ok := csiAllKeys [csiParamMode {M : mode , P : P0 }]; ok {
880887 ip .post (NewEventKey (ks .Key , "" , mod ))
@@ -891,7 +898,7 @@ func (ip *inputParser) handleCsi(mode rune, params []byte, intermediate []byte)
891898 }
892899 }
893900
894- if ks , ok := csiAllKeys [csiParamMode {M : mode , P : P0 }]; ok && ! hasLT {
901+ if ks , ok := csiAllKeys [csiParamMode {M : mode , P : P0 }]; ok {
895902 if mode == '~' && len (P ) > 1 && ks .Mod == ModNone {
896903 // apply modifiers if present
897904 ks .Mod = calcModifier (P [1 ])
0 commit comments