@@ -937,6 +937,15 @@ internal void ProcessWinChange ()
937
937
OnSizeChanged ( new SizeChangedEventArgs ( new ( Cols , Rows ) ) ) ;
938
938
}
939
939
}
940
+ static string ConvertToString ( ConsoleKeyInfo [ ] keyInfos )
941
+ {
942
+ char [ ] chars = new char [ keyInfos . Length ] ;
943
+ for ( int i = 0 ; i < keyInfos . Length ; i ++ )
944
+ {
945
+ chars [ i ] = keyInfos [ i ] . KeyChar ;
946
+ }
947
+ return new string ( chars ) ;
948
+ }
940
949
941
950
private void HandleEscSeqResponse (
942
951
ref int code ,
@@ -956,6 +965,17 @@ ref ConsoleKeyInfo [] cki
956
965
957
966
if ( wch2 == 0 || wch2 == 27 || wch2 == Curses . KeyMouse )
958
967
{
968
+ // Give ansi parser a chance to deal with the escape sequence
969
+ if ( cki != null && string . IsNullOrEmpty ( _parser . ProcessInput ( ConvertToString ( cki ) ) ) )
970
+ {
971
+ // Parser fully consumed all keys meaning keys are processed - job done
972
+ return ;
973
+ }
974
+
975
+ // Ansi parser could not deal with it either because it is not expecting
976
+ // the given terminator (e.g. mouse) or did not understand format somehow.
977
+ // Carry on with the older code for processing curses escape codes
978
+
959
979
// BUGBUG: Fix this nullable issue.
960
980
EscSeqUtils . DecodeEscSeq (
961
981
ref consoleKeyInfo ,
@@ -999,14 +1019,6 @@ ref ConsoleKeyInfo [] cki
999
1019
}
1000
1020
else
1001
1021
{
1002
- if ( cki != null )
1003
- {
1004
- foreach ( var c in cki )
1005
- {
1006
- _parser . ProcessInput ( c . KeyChar . ToString ( ) ) ;
1007
- }
1008
- }
1009
-
1010
1022
k = ConsoleKeyMapping . MapConsoleKeyInfoToKeyCode ( consoleKeyInfo ) ;
1011
1023
keyEventArgs = new Key ( k ) ;
1012
1024
OnKeyDown ( keyEventArgs ) ;
0 commit comments