Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More keys support with curses #111

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading