Skip to content

Commit

Permalink
More keys support with curses (#111)
Browse files Browse the repository at this point in the history
* More keys support with curses
* Automated JetBrains cleanup
  • Loading branch information
jinek authored Nov 27, 2023
1 parent ecb0a37 commit 43683fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
40 changes: 20 additions & 20 deletions src/Consolonia.GuiCS/binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ static void FindNCurses ()
cols_ptr = get_ptr ("COLS");
}

static public Window initscr ()
{
setlocale (LC_ALL, "");
FindNCurses ();

// Prevents the terminal from being locked after exiting.
reset_shell_mode ();

main_window = new Window (methods.initscr ());
try {
console_sharp_get_dims (out lines, out cols);
} catch (DllNotFoundException) {
endwin ();
Console.Error.WriteLine ("Unable to find the @MONO_CURSES@ native library\n" +
"this is different than the managed mono-curses.dll\n\n" +
"Typically you need to install to a LD_LIBRARY_PATH directory\n" +
"or DYLD_LIBRARY_PATH directory or run /sbin/ldconfig");
Environment.Exit (1);
static public Window initscr ()
{
setlocale (LC_ALL, "");
FindNCurses ();

// Prevents the terminal from being locked after exiting.
reset_shell_mode ();

main_window = new Window (methods.initscr ());
try {
console_sharp_get_dims (out lines, out cols);
} catch (DllNotFoundException) {
endwin ();
Console.Error.WriteLine ("Unable to find the @MONO_CURSES@ native library\n" +
"this is different than the managed mono-curses.dll\n\n" +
"Typically you need to install to a LD_LIBRARY_PATH directory\n" +
"or DYLD_LIBRARY_PATH directory or run /sbin/ldconfig");
Environment.Exit (1);
}
return main_window;
}
return main_window;
}

public static int Lines {
get {
Expand Down
17 changes: 16 additions & 1 deletion src/Consolonia.PlatformSupport/CursesConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ private static readonly FlagTranslator<Key, ConsoleKey>
(Key.Space, ConsoleKey.Spacebar),
(Key.Tab, ConsoleKey.Tab),
// Proposed by ChatGPT, I've found supporting source: https://devblogs.microsoft.com/dotnet/console-readkey-improvements-in-net-7/
(Key.Unknown, ConsoleKey.NoName)
(Key.Unknown, ConsoleKey.NoName),
((Key)46, ConsoleKey.OemPeriod),
// rest is by chatGPT
((Key)44, ConsoleKey.OemComma),
((Key)59, ConsoleKey.Oem1),
((Key)47, ConsoleKey.Oem2), // Oem2 usually represents the '/' key
((Key)92, ConsoleKey.Oem5), // Oem5 usually represents the '\\' key
((Key)61, ConsoleKey.OemPlus), // OemPlus might be used for both '=' and '+'
((Key)45, ConsoleKey.OemMinus),
((Key)91, ConsoleKey.Oem4), // '[' key
((Key)93, ConsoleKey.Oem6), // ']' key
((Key)39, ConsoleKey.Oem7) // '\'' key
});

private static readonly FlagTranslator<Curses.Event, RawInputModifiers>
Expand Down Expand Up @@ -389,6 +400,10 @@ private void RaiseKeyPressInternal(Key key)
char character;
ConsoleKey consoleKey =
KeyFlagTranslator.Translate(key & ~Key.CtrlMask & ~Key.ShiftMask & ~Key.AltMask, true);

if (consoleKey == ConsoleKey.NoName)
return;

if (consoleKey == default)
{
bool _ = Enum.TryParse(key.ToString(), true, out consoleKey);
Expand Down

0 comments on commit 43683fc

Please sign in to comment.