Skip to content

Commit d063873

Browse files
committed
Give ansi parser first crack at decode esc seq
1 parent 58a5e27 commit d063873

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,15 @@ internal void ProcessWinChange ()
937937
OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows)));
938938
}
939939
}
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+
}
940949

941950
private void HandleEscSeqResponse (
942951
ref int code,
@@ -956,6 +965,17 @@ ref ConsoleKeyInfo [] cki
956965

957966
if (wch2 == 0 || wch2 == 27 || wch2 == Curses.KeyMouse)
958967
{
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+
959979
// BUGBUG: Fix this nullable issue.
960980
EscSeqUtils.DecodeEscSeq (
961981
ref consoleKeyInfo,
@@ -999,14 +1019,6 @@ ref ConsoleKeyInfo [] cki
9991019
}
10001020
else
10011021
{
1002-
if (cki != null)
1003-
{
1004-
foreach (var c in cki)
1005-
{
1006-
_parser.ProcessInput (c.KeyChar.ToString());
1007-
}
1008-
}
1009-
10101022
k = ConsoleKeyMapping.MapConsoleKeyInfoToKeyCode (consoleKeyInfo);
10111023
keyEventArgs = new Key (k);
10121024
OnKeyDown (keyEventArgs);

0 commit comments

Comments
 (0)