Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
9897bb9
Support for remapping basic unicode keychars that come from OS with C…
tznind Sep 17, 2022
b0c2085
Added TryParseConsoleKey for better parsing
tznind Sep 18, 2022
0304656
Added single and double quotes
tznind Sep 19, 2022
0b2bdb0
Change TryRemapPacketKey to map to `Key` instead of `ConsoleKey`
tznind Sep 19, 2022
35e79a9
Tidy up layout and fix old inaccurate comment
tznind Sep 19, 2022
ba29d55
Merge branch 'develop' into vkpacket
tznind Sep 20, 2022
bb61870
Removed dead code. Packet vk is only used for symbols, never escape …
tznind Sep 20, 2022
a67da71
Merge branch 'vkpacket' of https://github.com/tznind/gui.cs into vkpa…
tznind Sep 20, 2022
98441c5
Updated tests for cleaner representation of new functionality
tznind Sep 20, 2022
ecfd9c1
WIP fix TryRemapPacketKey to correctly apply Alt/Ctrl mask
tznind Sep 21, 2022
61f5b09
Only the Shift key must be handled with the Packet key.
BDisp Sep 21, 2022
eebba5e
Merge pull request #125 from BDisp/vkpacket-fix
tznind Sep 21, 2022
1dd9ae1
Excluding the shift key when IsLetterOrDigit, IsSymbol and IsPunctuat…
BDisp Sep 25, 2022
a88c355
Merge pull request #126 from BDisp/vkpacket-fix-2
tznind Sep 26, 2022
5e26651
Removed packages.config (defunct). Relnotes for 1.8.1
tig Sep 21, 2022
8e71782
Added help menu from the UICatalog into the StandaloneExample.
BDisp Sep 21, 2022
532bbe1
Fixes #2053. MessageBox.Query still not wrapping with v1.8.0 on windo…
BDisp Sep 21, 2022
ed31c42
Bump actions/setup-dotnet from 1 to 2.1.1
dependabot[bot] Sep 26, 2022
f1253ae
Bump Microsoft.NET.Test.Sdk from 17.3.1 to 17.3.2
dependabot[bot] Sep 26, 2022
e389a7b
Fixes #2061. WindowsDriver sometimes returns badly mouse flag zero on…
BDisp Sep 23, 2022
2dcbe74
Fixes #2064. mouseGrabView must have a track to allow the views who u…
BDisp Sep 24, 2022
ef12b60
Replacing to MouseGrabView.
BDisp Sep 24, 2022
6956246
Fixes #2071. DrawContentComplete event is never called from the base …
BDisp Sep 28, 2022
b764669
Bump ReactiveMarbles.ObservableEvents.SourceGenerator
dependabot[bot] Sep 27, 2022
e6e6dbb
Fixes #2069. KeyDown and KeyUp events must run before OnKeyDown and O…
BDisp Sep 27, 2022
c54483e
Adding a more realistic key down/up event with null key.
BDisp Sep 28, 2022
b4a0470
Bump actions/setup-dotnet from 2.1.1 to 3.0.1
dependabot[bot] Oct 10, 2022
0588c3a
Deleted demo.cs; changed to Example.cs from README
tig Oct 14, 2022
a9444e6
Removed ancient StandaloneExample
tig Oct 14, 2022
8e4cb50
readme tweaks
tig Oct 14, 2022
94b596e
fix typo
tig Oct 14, 2022
a8511f3
fixes link to OCGV
tig Oct 14, 2022
fb1491f
noted demo.cs deletion with link to history
tig Oct 14, 2022
c3b4aeb
Added templates to readme
tig Oct 17, 2022
7a506dd
Bump actions/setup-dotnet from 3.0.1 to 3.0.2
dependabot[bot] Oct 17, 2022
ff96e09
Bump gittools/actions from 0.9.13 to 0.9.14
dependabot[bot] Oct 17, 2022
7b16a93
Non breaking implementation of cancellable root mouse events
tznind Oct 19, 2022
5005434
Fix copy/paste error in SuppressKey test
tznind Oct 19, 2022
46694ff
Change `MouseEvent` to a mutable class (previously struct) and added …
tznind Oct 19, 2022
e7efa40
Updated docs and made MouseEvent fields into properties for futurepro…
tznind Oct 19, 2022
7ce2cf3
Added Rider/Resharper settings file that enforces the formatting and …
pavkam Oct 18, 2022
c8eac9c
Improves the TabView minimum size and added more unit tests.
BDisp Oct 19, 2022
e87cd22
Makes Notepad look better and fixes bugs
tig Oct 19, 2022
b4f7fc0
fixed shortcut for save as
tig Oct 19, 2022
e809aff
refactoring menutests
tig Oct 20, 2022
8e54135
Fix locking for the entire RunIdle callback execution
tznind Oct 13, 2022
b1ece93
cleanup and fix docs in View class
pavkam Oct 18, 2022
bd5b122
Correct for the comments on the PR and removed two unused imports.
pavkam Oct 19, 2022
3a19822
Fixes 2094. View does not clear it's background.
BDisp Oct 19, 2022
c8f3939
Fix unit tests.
BDisp Oct 19, 2022
55d4a78
Fixed tons of little doc typos
tig Oct 20, 2022
4646b72
further progress
tig Oct 20, 2022
68697c0
Finished refactoring tests
tig Oct 20, 2022
2c63d92
removed test code from Notepad
tig Oct 20, 2022
327980d
Simplify MakePrintable by using AND and avoiding converting to string…
pavkam Oct 19, 2022
fec4c28
Fixes #2081. Clipboard unit tests sometimes fail with WSL.
BDisp Oct 12, 2022
8ddbed9
Added some documentation into the testenvironments.json file.
BDisp Oct 20, 2022
f9a3817
documenting behavior
tig Oct 21, 2022
5f2ec20
added constants to MenuBar
tig Oct 21, 2022
57cef55
made code clearer
tig Oct 21, 2022
09a6490
made code clearer
tig Oct 21, 2022
9ef5140
more doc improvements
tig Oct 21, 2022
40c1faf
testing improve this doc...
tig Oct 21, 2022
05384c8
Fixes #2121. ContextMenu: When open, Shift-F10 should close menu.
BDisp Oct 21, 2022
54ab534
Fixes HotColor for non-activated menus
tig Oct 21, 2022
abdacea
backed out testing change
tig Oct 21, 2022
4739f6a
Add menu toggle for DesiredCursorVisibility to TreeView UICatalog sce…
tznind Oct 21, 2022
62869c9
Change TreeView default cursor to invisible and force invisible only …
tznind Oct 22, 2022
cc1691d
Fixes #2135. Character Map scenario doesn't show the content view.
BDisp Oct 25, 2022
8f7b038
Added one more unit test.
BDisp Oct 26, 2022
598be52
Added ContentOffset and ContentSize unit tests.
BDisp Oct 26, 2022
8d9d96f
Merge develop and resolving conflicts.
BDisp Oct 30, 2022
15a7e37
Fixes #2076. Running alone the SetColors_Changes_Colors unit test wil…
BDisp Oct 9, 2022
abd9d47
Added support to handle with the virtual packet key.
BDisp Oct 30, 2022
2562ad9
Merge pull request #128 from BDisp/vkpacket-fix3
tznind Oct 30, 2022
e0504dd
Removed unnecessary method.
BDisp Oct 30, 2022
cbd4a5a
Merge pull request #134 from BDisp/vkpacket-fix4
tznind Oct 30, 2022
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
50 changes: 38 additions & 12 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ KeyModifiers MapKeyModifiers (Key key)
return keyModifiers;
}

void ProcessInput (Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
void ProcessInput ()
{
int wch;
var code = Curses.get_wch (out wch);
Expand Down Expand Up @@ -787,19 +787,23 @@ void ProcessInput (Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler,
}

Action<KeyEvent> keyHandler;
Action<KeyEvent> keyDownHandler;
Action<KeyEvent> keyUpHandler;
Action<MouseEvent> mouseHandler;

public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
{
// Note: Curses doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
Curses.timeout (0);
this.keyHandler = keyHandler;
this.keyDownHandler = keyDownHandler;
this.keyUpHandler = keyUpHandler;
this.mouseHandler = mouseHandler;

var mLoop = mainLoop.Driver as UnixMainLoop;

mLoop.AddWatch (0, UnixMainLoop.Condition.PollIn, x => {
ProcessInput (keyHandler, keyDownHandler, keyUpHandler, mouseHandler);
ProcessInput ();
return true;
});

Expand Down Expand Up @@ -1128,26 +1132,48 @@ public override bool EnsureCursorVisibility ()
return false;
}

public override void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
public override void SendKeys (char keyChar, ConsoleKey consoleKey, bool shift, bool alt, bool control)
{
Key k;
Key key;

if ((shift || alt || control)
&& keyChar - (int)Key.Space >= (uint)Key.A && keyChar - (int)Key.Space <= (uint)Key.Z) {
k = (Key)(keyChar - (uint)Key.Space);
if (consoleKey == ConsoleKey.Packet) {
ConsoleModifiers mod = new ConsoleModifiers ();
if (shift) {
mod |= ConsoleModifiers.Shift;
}
if (alt) {
mod |= ConsoleModifiers.Alt;
}
if (control) {
mod |= ConsoleModifiers.Control;
}
var kchar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (keyChar, mod, out uint ckey, out _);
key = ConsoleKeyMapping.MapConsoleKeyToKey ((ConsoleKey)ckey, out bool mappable);
if (mappable) {
key = (Key)kchar;
}
} else {
k = (Key)keyChar;
key = (Key)keyChar;
}

KeyModifiers km = new KeyModifiers ();
if (shift) {
k |= Key.ShiftMask;
if (keyChar == 0) {
key |= Key.ShiftMask;
}
km.Shift = shift;
}
if (alt) {
k |= Key.AltMask;
key |= Key.AltMask;
km.Alt = alt;
}
if (control) {
k |= Key.CtrlMask;
key |= Key.CtrlMask;
km.Ctrl = control;
}
keyHandler (new KeyEvent (k, MapKeyModifiers (k)));
keyDownHandler (new KeyEvent (key, km));
keyHandler (new KeyEvent (key, km));
keyUpHandler (new KeyEvent (key, km));
}

public override bool GetColors (int value, out Color foreground, out Color background)
Expand Down
17 changes: 11 additions & 6 deletions Terminal.Gui/ConsoleDrivers/FakeDriver/FakeConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ public static class FakeConsole {
//
// T:System.IO.IOException:
// An I/O error occurred.

static ConsoleColor _defaultBackgroundColor = ConsoleColor.Black;

/// <summary>
///
/// </summary>
public static ConsoleColor BackgroundColor { get; set; } = _defaultBackgroundColor;
static ConsoleColor _defaultBackgroundColor = ConsoleColor.Black;

//
// Summary:
Expand All @@ -187,11 +189,13 @@ public static class FakeConsole {
//
// T:System.IO.IOException:
// An I/O error occurred.

static ConsoleColor _defaultForegroundColor = ConsoleColor.Gray;

/// <summary>
///
/// </summary>
public static ConsoleColor ForegroundColor { get; set; } = _defaultForegroundColor;
static ConsoleColor _defaultForegroundColor = ConsoleColor.Gray;
//
// Summary:
// Gets or sets the height of the buffer area.
Expand Down Expand Up @@ -541,6 +545,9 @@ public static void Beep (int frequency, int duration)
// Exceptions:
// T:System.IO.IOException:
// An I/O error occurred.

static char [,] _buffer = new char [WindowWidth, WindowHeight];

/// <summary>
///
/// </summary>
Expand All @@ -550,8 +557,6 @@ public static void Clear ()
SetCursorPosition (0, 0);
}

static char [,] _buffer = new char [WindowWidth, WindowHeight];

//
// Summary:
// Copies a specified source area of the screen buffer to a specified destination
Expand Down Expand Up @@ -811,9 +816,9 @@ public static int Read ()
public static ConsoleKeyInfo ReadKey (bool intercept)
{
if (MockKeyPresses.Count > 0) {
return MockKeyPresses.Pop();
return MockKeyPresses.Pop ();
} else {
return new ConsoleKeyInfo ('\0', (ConsoleKey)'\0', false,false,false);
return new ConsoleKeyInfo ('\0', (ConsoleKey)'\0', false, false, false);
}
}

Expand Down
33 changes: 32 additions & 1 deletion Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,31 @@ public override void SetAttribute (Attribute c)
currentAttribute = c;
}

public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
{
if (consoleKeyInfo.Key != ConsoleKey.Packet) {
return consoleKeyInfo;
}

var mod = consoleKeyInfo.Modifiers;
var shift = (mod & ConsoleModifiers.Shift) != 0;
var alt = (mod & ConsoleModifiers.Alt) != 0;
var control = (mod & ConsoleModifiers.Control) != 0;

var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (consoleKeyInfo.KeyChar, consoleKeyInfo.Modifiers, out uint virtualKey, out _);

return new ConsoleKeyInfo ((char)keyChar, (ConsoleKey)virtualKey, shift, alt, control);
}

Key MapKey (ConsoleKeyInfo keyInfo)
{
switch (keyInfo.Key) {
case ConsoleKey.Escape:
return MapKeyModifiers (keyInfo, Key.Esc);
case ConsoleKey.Tab:
return keyInfo.Modifiers == ConsoleModifiers.Shift ? Key.BackTab : Key.Tab;
case ConsoleKey.Clear:
return MapKeyModifiers (keyInfo, Key.Clear);
case ConsoleKey.Home:
return MapKeyModifiers (keyInfo, Key.Home);
case ConsoleKey.End:
Expand All @@ -289,6 +307,8 @@ Key MapKey (ConsoleKeyInfo keyInfo)
return MapKeyModifiers (keyInfo, Key.DeleteChar);
case ConsoleKey.Insert:
return MapKeyModifiers (keyInfo, Key.InsertChar);
case ConsoleKey.PrintScreen:
return MapKeyModifiers (keyInfo, Key.PrintScreen);

case ConsoleKey.Oem1:
case ConsoleKey.Oem2:
Expand Down Expand Up @@ -318,6 +338,9 @@ Key MapKey (ConsoleKeyInfo keyInfo)
if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
return (Key)(((uint)Key.AltMask) | ((uint)Key.A + delta));
}
if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
return MapKeyModifiers (keyInfo, (Key)((uint)Key.A + delta));
}
if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
if (keyInfo.KeyChar == 0) {
return (Key)(((uint)Key.AltMask | (uint)Key.CtrlMask) | ((uint)Key.A + delta));
Expand All @@ -335,9 +358,14 @@ Key MapKey (ConsoleKeyInfo keyInfo)
if (keyInfo.Modifiers == ConsoleModifiers.Control) {
return (Key)(((uint)Key.CtrlMask) | ((uint)Key.D0 + delta));
}
if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
}
if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
}
}
return (Key)((uint)keyInfo.KeyChar);
}
if (key >= ConsoleKey.F1 && key <= ConsoleKey.F12) {
Expand Down Expand Up @@ -387,6 +415,9 @@ public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandle

void ProcessInput (ConsoleKeyInfo consoleKey)
{
if (consoleKey.Key == ConsoleKey.Packet) {
consoleKey = FromVKPacketToKConsoleKeyInfo (consoleKey);
}
keyModifiers = new KeyModifiers ();
if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Shift)) {
keyModifiers.Shift = true;
Expand Down
48 changes: 36 additions & 12 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
int foundPoint = 0;
string value = "";
var kChar = GetKeyCharArray (cki);
//System.Diagnostics.Debug.WriteLine ($"kChar: {new string (kChar)}");
for (int i = 0; i < kChar.Length; i++) {
var c = kChar [i];
if (c == '<') {
Expand Down Expand Up @@ -560,6 +561,8 @@ void GetMouseEvent (ConsoleKeyInfo [] cki)
// isButtonPressed = false;
//}

//System.Diagnostics.Debug.WriteLine ($"buttonCode: {buttonCode}");

switch (buttonCode) {
case 0:
case 8:
Expand Down Expand Up @@ -1610,6 +1613,22 @@ public override void SetAttribute (Attribute c)
currentAttribute = c;
}

public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
{
if (consoleKeyInfo.Key != ConsoleKey.Packet) {
return consoleKeyInfo;
}

var mod = consoleKeyInfo.Modifiers;
var shift = (mod & ConsoleModifiers.Shift) != 0;
var alt = (mod & ConsoleModifiers.Alt) != 0;
var control = (mod & ConsoleModifiers.Control) != 0;

var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (consoleKeyInfo.KeyChar, consoleKeyInfo.Modifiers, out uint virtualKey, out _);

return new ConsoleKeyInfo ((char)keyChar, (ConsoleKey)virtualKey, shift, alt, control);
}

Key MapKey (ConsoleKeyInfo keyInfo)
{
MapKeyModifiers (keyInfo, (Key)keyInfo.Key);
Expand Down Expand Up @@ -1687,7 +1706,7 @@ Key MapKey (ConsoleKeyInfo keyInfo)
return (Key)(((uint)Key.CtrlMask) | ((uint)Key.D0 + delta));
}
if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30 || keyInfo.KeyChar == ((uint)Key.D0 + delta)) {
return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
}
}
Expand Down Expand Up @@ -1754,14 +1773,23 @@ void ProcessInput (NetEvents.InputResult inputEvent)
{
switch (inputEvent.EventType) {
case NetEvents.EventType.Key:
ConsoleKeyInfo consoleKeyInfo = inputEvent.ConsoleKeyInfo;
if (consoleKeyInfo.Key == ConsoleKey.Packet) {
consoleKeyInfo = FromVKPacketToKConsoleKeyInfo (consoleKeyInfo);
}
keyModifiers = new KeyModifiers ();
var map = MapKey (inputEvent.ConsoleKeyInfo);
var map = MapKey (consoleKeyInfo);
if (map == (Key)0xffffffff) {
return;
}
keyDownHandler (new KeyEvent (map, keyModifiers));
keyHandler (new KeyEvent (map, keyModifiers));
keyUpHandler (new KeyEvent (map, keyModifiers));
if (map == Key.Null) {
keyDownHandler (new KeyEvent (map, keyModifiers));
keyUpHandler (new KeyEvent (map, keyModifiers));
} else {
keyDownHandler (new KeyEvent (map, keyModifiers));
keyHandler (new KeyEvent (map, keyModifiers));
keyUpHandler (new KeyEvent (map, keyModifiers));
}
break;
case NetEvents.EventType.Mouse:
mouseHandler (ToDriverMouse (inputEvent.MouseEvent));
Expand Down Expand Up @@ -1804,6 +1832,8 @@ void ChangeWin ()

MouseEvent ToDriverMouse (NetEvents.MouseEvent me)
{
//System.Diagnostics.Debug.WriteLine ($"X: {me.Position.X}; Y: {me.Position.Y}; ButtonState: {me.ButtonState}");

MouseFlags mouseFlag = 0;

if ((me.ButtonState & NetEvents.MouseButtonState.Button1Pressed) != 0) {
Expand Down Expand Up @@ -1935,14 +1965,8 @@ public override bool EnsureCursorVisibility ()
public override void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
{
NetEvents.InputResult input = new NetEvents.InputResult ();
ConsoleKey ck;
if (char.IsLetter (keyChar)) {
ck = key;
} else {
ck = (ConsoleKey)'\0';
}
input.EventType = NetEvents.EventType.Key;
input.ConsoleKeyInfo = new ConsoleKeyInfo (keyChar, ck, shift, alt, control);
input.ConsoleKeyInfo = new ConsoleKeyInfo (keyChar, key, shift, alt, control);

try {
ProcessInput (input);
Expand Down
Loading