From a3c37ebc295e0d0d033d2cb6638a665b63461614 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 00:48:19 +0000 Subject: [PATCH] Automated JetBrains cleanup Co-authored-by: <+@users.noreply.github.com> --- .../CursesConsole.cs | 360 +++++++++--------- 1 file changed, 179 insertions(+), 181 deletions(-) diff --git a/src/Consolonia.PlatformSupport/CursesConsole.cs b/src/Consolonia.PlatformSupport/CursesConsole.cs index 135e4f33..4ecc2c6c 100644 --- a/src/Consolonia.PlatformSupport/CursesConsole.cs +++ b/src/Consolonia.PlatformSupport/CursesConsole.cs @@ -164,7 +164,7 @@ private void ProcessInput() _keyModifiers = new KeyModifiers(); var k = Key.Unknown; - + if (code == Curses.KEY_CODE_YES) { switch (wch) @@ -217,199 +217,197 @@ private void ProcessInput() { // Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey case 27: + { + Curses.timeout(200); + + code = Curses.get_wch(out int wch2); + + if (code == Curses.KEY_CODE_YES) k = Key.AltMask | MapCursesKey(wch); + + if (code == 0) { - Curses.timeout(200); - - code = Curses.get_wch(out int wch2); - - if (code == Curses.KEY_CODE_YES) k = Key.AltMask | MapCursesKey(wch); - - if (code == 0) - { - //KeyEvent key; - - // The ESC-number handling, debatable. - // Simulates the AltMask itself by pressing Alt + Space. - if (wch2 == (int)Key.Space) - k = Key.AltMask; - else if (wch2 - (int)Key.Space >= (uint)Key.A && wch2 - (int)Key.Space <= (uint)Key.Z) - k = (Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)); - else if (wch2 >= (uint)Key.A - 64 && wch2 <= (uint)Key.Z - 64) - k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + (wch2 + 64)); - else if (wch2 >= (uint)Key.D0 && wch2 <= (uint)Key.D9) - k = (Key)((uint)Key.AltMask + (uint)Key.D0 + (wch2 - (uint)Key.D0)); - else - switch (wch2) + //KeyEvent key; + + // The ESC-number handling, debatable. + // Simulates the AltMask itself by pressing Alt + Space. + if (wch2 == (int)Key.Space) + k = Key.AltMask; + else if (wch2 - (int)Key.Space >= (uint)Key.A && wch2 - (int)Key.Space <= (uint)Key.Z) + k = (Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)); + else if (wch2 >= (uint)Key.A - 64 && wch2 <= (uint)Key.Z - 64) + k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + (wch2 + 64)); + else if (wch2 >= (uint)Key.D0 && wch2 <= (uint)Key.D9) + k = (Key)((uint)Key.AltMask + (uint)Key.D0 + (wch2 - (uint)Key.D0)); + else + switch (wch2) + { + case 27: + k = (Key)wch2; + break; + case Curses.KEY_CODE_SEQ: { - case 27: - k = (Key)wch2; - break; - case Curses.KEY_CODE_SEQ: - { - int[] c = null; - while (code == 0) - { - code = Curses.get_wch(out wch2); - if (wch2 <= 0) continue; - int length = 1; - if (c != null) - length += c.Length; - Array.Resize(ref c, length); - - c[^1] = wch2; - } + int[] c = null; + while (code == 0) + { + code = Curses.get_wch(out wch2); + if (wch2 <= 0) continue; + int length = 1; + if (c != null) + length += c.Length; + Array.Resize(ref c, length); + + c[^1] = wch2; + } + + switch (c![0]) + { + case 49 when c[1] == 59 && c[2] == 55 && c[3] >= 80 && c[3] <= 83: + // Ctrl+Alt+(F1 - F4) + wch2 = c[3] + 185; + k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); + break; + case 49 + when c[2] == 59 && c[3] == 55 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: + // Ctrl+Alt+(F5 - F8) + wch2 = c[1] == 53 ? c[1] + 216 : c[1] + 215; + k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); + break; + case 50 + when c[2] == 59 && c[3] == 55 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: + // Ctrl+Alt+(F9 - F12) + wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; + k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); + break; + case 49 when c[1] == 59 && c[2] == 56 && c[3] >= 80 && c[3] <= 83: + // Ctrl+Shift+Alt+(F1 - F4) + wch2 = c[3] + 185; + k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 49 + when c[2] == 59 && c[3] == 56 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: + // Ctrl+Shift+Alt+(F5 - F8) + wch2 = c[1] == 53 ? c[1] + 216 : c[1] + 215; + k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 50 + when c[2] == 59 && c[3] == 56 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: + // Ctrl+Shift+Alt+(F9 - F12) + wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; + k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 49 when c[1] == 59 && c[2] == 52 && c[3] == 83: + // Shift+Alt+(F4) + wch2 = 268; + k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 49 + when c[2] == 59 && c[3] == 52 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: + // Shift+Alt+(F5 - F8) + wch2 = c[1] < 55 ? c[1] + 216 : c[1] + 215; + k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 50 + when c[2] == 59 && c[3] == 52 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: + // Shift+Alt+(F9 - F12) + wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; + k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); + break; + case 54 when c[1] == 59 && c[2] == 56 && c[3] == 126: + // Shift+Ctrl+Alt+KeyNPage + k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageDown; + break; + case 53 when c[1] == 59 && c[2] == 56 && c[3] == 126: + // Shift+Ctrl+Alt+KeyPPage + k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageUp; + break; + case 49 when c[1] == 59 && c[2] == 56 && c[3] == 72: + // Shift+Ctrl+Alt+KeyHome + k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.Home; + break; + case 49 when c[1] == 59 && c[2] == 56 && c[3] == 70: + // Shift+Ctrl+Alt+KeyEnd + k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.End; + break; - switch (c![0]) + // ESC [200~ + case 50 when c[1] == 48 && c[2] == 48 && c[3] == 126: + var sb = new StringBuilder(); + for (int i = 4; i < c.Length; i++) sb.Append((char)c[i]); + string bufferText = sb.ToString(); + int index = bufferText.IndexOf("\u001b[201~", StringComparison.Ordinal); + if (index > 0) { - case 49 when c[1] == 59 && c[2] == 55 && c[3] >= 80 && c[3] <= 83: - // Ctrl+Alt+(F1 - F4) - wch2 = c[3] + 185; - k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); - break; - case 49 - when c[2] == 59 && c[3] == 55 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: - // Ctrl+Alt+(F5 - F8) - wch2 = c[1] == 53 ? c[1] + 216 : c[1] + 215; - k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); - break; - case 50 - when c[2] == 59 && c[3] == 55 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: - // Ctrl+Alt+(F9 - F12) - wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; - k = Key.CtrlMask | Key.AltMask | MapCursesKey(wch2); - break; - case 49 when c[1] == 59 && c[2] == 56 && c[3] >= 80 && c[3] <= 83: - // Ctrl+Shift+Alt+(F1 - F4) - wch2 = c[3] + 185; - k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 49 - when c[2] == 59 && c[3] == 56 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: - // Ctrl+Shift+Alt+(F5 - F8) - wch2 = c[1] == 53 ? c[1] + 216 : c[1] + 215; - k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 50 - when c[2] == 59 && c[3] == 56 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: - // Ctrl+Shift+Alt+(F9 - F12) - wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; - k = Key.CtrlMask | Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 49 when c[1] == 59 && c[2] == 52 && c[3] == 83: - // Shift+Alt+(F4) - wch2 = 268; - k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 49 - when c[2] == 59 && c[3] == 52 && c[4] == 126 && c[1] >= 53 && c[1] <= 57: - // Shift+Alt+(F5 - F8) - wch2 = c[1] < 55 ? c[1] + 216 : c[1] + 215; - k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 50 - when c[2] == 59 && c[3] == 52 && c[4] == 126 && c[1] >= 48 && c[1] <= 52: - // Shift+Alt+(F9 - F12) - wch2 = c[1] < 51 ? c[1] + 225 : c[1] + 224; - k = Key.ShiftMask | Key.AltMask | MapCursesKey(wch2); - break; - case 54 when c[1] == 59 && c[2] == 56 && c[3] == 126: - // Shift+Ctrl+Alt+KeyNPage - k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageDown; - break; - case 53 when c[1] == 59 && c[2] == 56 && c[3] == 126: - // Shift+Ctrl+Alt+KeyPPage - k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.PageUp; - break; - case 49 when c[1] == 59 && c[2] == 56 && c[3] == 72: - // Shift+Ctrl+Alt+KeyHome - k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.Home; - break; - case 49 when c[1] == 59 && c[2] == 56 && c[3] == 70: - // Shift+Ctrl+Alt+KeyEnd - k = Key.ShiftMask | Key.CtrlMask | Key.AltMask | Key.End; - break; - - // ESC [200~ - case 50 when c[1] == 48 && c[2] == 48 && c[3] == 126: - StringBuilder sb = new StringBuilder(); - for (int i = 4; i < c.Length; i++) - { - sb.Append((char)c[i]); - } - var bufferText = sb.ToString(); - var index = bufferText.IndexOf("\u001b[201~", StringComparison.Ordinal); - if (index > 0) - { - var text = bufferText[..--index]; - RaiseTextInput(text, (ulong)Stopwatch.GetTimestamp()); - } - break; - - default: - k = MapCursesKey(wch2); - break; + string text = bufferText[..--index]; + RaiseTextInput(text, (ulong)Stopwatch.GetTimestamp()); } break; - } - default: - { - // Unfortunately there are no way to differentiate Ctrl+Alt+alfa and Ctrl+Shift+Alt+alfa. - if (((Key)wch2 & Key.CtrlMask) != 0) _keyModifiers.Ctrl = true; - - if (wch2 == 0) - { - k = Key.CtrlMask | Key.AltMask | Key.Space; - } - // ReSharper disable once ConditionIsAlwaysTrueOrFalse todo: check why - else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) - { - _keyModifiers.Shift = true; - _keyModifiers.Alt = true; - } - else if (wch2 < 256) - { - k = (Key)wch2; - _keyModifiers.Alt = true; - } - else - { - k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + wch2); - } + default: + k = MapCursesKey(wch2); break; - } - } - } - else - { - k = Key.Esc; - } + } - break; + break; + } + default: + { + // Unfortunately there are no way to differentiate Ctrl+Alt+alfa and Ctrl+Shift+Alt+alfa. + if (((Key)wch2 & Key.CtrlMask) != 0) _keyModifiers.Ctrl = true; + + if (wch2 == 0) + { + k = Key.CtrlMask | Key.AltMask | Key.Space; + } + // ReSharper disable once ConditionIsAlwaysTrueOrFalse todo: check why + else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) + { + _keyModifiers.Shift = true; + _keyModifiers.Alt = true; + } + else if (wch2 < 256) + { + k = (Key)wch2; + _keyModifiers.Alt = true; + } + else + { + k = (Key)((uint)(Key.AltMask | Key.CtrlMask) + wch2); + } + + break; + } + } } + else + { + k = Key.Esc; + } + + break; + } case Curses.KeyTab: k = MapCursesKey(wch); break; default: + { + // Unfortunately there are no way to differentiate Ctrl+alfa and Ctrl+Shift+alfa. + k = (Key)wch; + if (wch == 0) { - // Unfortunately there are no way to differentiate Ctrl+alfa and Ctrl+Shift+alfa. - k = (Key)wch; - if (wch == 0) - { - k = Key.CtrlMask | Key.Space; - } - else if (wch >= (uint)Key.A - 64 && wch <= (uint)Key.Z - 64) - { - if ((Key)(wch + 64) != Key.J) k = Key.CtrlMask | (Key)(wch + 64); - } - else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) - { - _keyModifiers.Shift = true; - } - - break; + k = Key.CtrlMask | Key.Space; + } + else if (wch >= (uint)Key.A - 64 && wch <= (uint)Key.Z - 64) + { + if ((Key)(wch + 64) != Key.J) k = Key.CtrlMask | (Key)(wch + 64); } + else if (wch >= (uint)Key.A && wch <= (uint)Key.Z) + { + _keyModifiers.Shift = true; + } + + break; + } } RaiseKeyPressInternal(k); @@ -433,10 +431,10 @@ private void RaiseKeyPressInternal(Key key) case ConsoleKey.NoName: return; case 0: - { - bool _ = Enum.TryParse(key.ToString(), true, out consoleKey); - break; - } + { + bool _ = Enum.TryParse(key.ToString(), true, out consoleKey); + break; + } } if (((uint)keyValue & (uint)Key.CharMask) > 27)