Skip to content

Commit

Permalink
Do not deadlock in Stop if invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Dec 14, 2024
1 parent e832d61 commit 293fe4e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Terminal.Gui/ConsoleDrivers/V2/MainLoopCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ public void Stop ()
{
tokenSource.Cancel();

// Wait for both tasks to complete
Task.WhenAll (_inputTask, _loopTask).Wait ();
if (_loopTask.Id == Task.CurrentId)
{
// Cannot wait for loop to finish because we are actively executing on that thread
Task.WhenAll (_inputTask).Wait ();
}
else
{
// Wait for both tasks to complete
Task.WhenAll (_inputTask, _loopTask).Wait ();
}

}
}
44 changes: 43 additions & 1 deletion Terminal.Gui/ConsoleDrivers/V2/WindowsInputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,49 @@ protected override void Process (InputRecord inputEvent)
/// <inheritdoc />
protected override void ProcessAfterParsing (InputRecord input)
{
var key = (Key)input.KeyEvent.UnicodeChar;
Key key;
if (input.KeyEvent.UnicodeChar == '\0')
{
key = input.KeyEvent.wVirtualKeyCode switch
{
VK.DOWN => Key.CursorDown,
VK.UP => Key.CursorUp,
VK.LEFT => Key.CursorLeft,
VK.RIGHT => Key.CursorRight,
VK.BACK => Key.Backspace,
VK.TAB => Key.Tab,
VK.F1 => Key.F1,
VK.F2 => Key.F2,
VK.F3 => Key.F3,
VK.F4 => Key.F4,
VK.F5 => Key.F5,
VK.F6 => Key.F6,
VK.F7 => Key.F7,
VK.F8 => Key.F8,
VK.F9 => Key.F9,
VK.F10 => Key.F10,
VK.F11 => Key.F11,
VK.F12 => Key.F12,
VK.F13 => Key.F13,
VK.F14 => Key.F14,
VK.F15 => Key.F15,
VK.F16 => Key.F16,
VK.F17 => Key.F17,
VK.F18 => Key.F18,
VK.F19 => Key.F19,
VK.F20 => Key.F20,
VK.F21 => Key.F21,
VK.F22 => Key.F22,
VK.F23 => Key.F23,
VK.F24 => Key.F24,
_ => (Key)'\0'
};
}
else
{
key = input.KeyEvent.UnicodeChar;
}

OnKeyDown (key);
OnKeyUp (key);
}
Expand Down
6 changes: 6 additions & 0 deletions UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,12 @@ public UICatalogTopLevel ()

public void ConfigChanged ()
{
if (MenuBar == null)
{
// View is probably disposed
return;
}

if (_topLevelColorScheme == null || !Colors.ColorSchemes.ContainsKey (_topLevelColorScheme))
{
_topLevelColorScheme = "Base";
Expand Down

0 comments on commit 293fe4e

Please sign in to comment.