From a50d79bd7bdfbdeac26bd2e8378a16307555370c Mon Sep 17 00:00:00 2001 From: giladlevi Date: Wed, 4 Sep 2019 06:13:53 +0300 Subject: [PATCH] bugfix in Button.ProcessKey and expose a new function for all drivers (#253) * added a public api function called SetTerminalResized for drivers * bugfix: overflow exception has occurred on (Rune)c when c is an integer => casting to uint solved the problem * Apply suggestions from code review Co-Authored-By: Marius Ungureanu --- Terminal.Gui/Drivers/ConsoleDriver.cs | 7 +++++++ Terminal.Gui/Drivers/CursesDriver.cs | 6 ++---- Terminal.Gui/Views/Button.cs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs index 6285ca971..7ab4139f5 100644 --- a/Terminal.Gui/Drivers/ConsoleDriver.cs +++ b/Terminal.Gui/Drivers/ConsoleDriver.cs @@ -253,6 +253,8 @@ namespace Terminal.Gui { /// ConsoleDriver is an abstract class that defines the requirements for a console driver. One implementation if the CursesDriver, and another one uses the .NET Console one. /// public abstract class ConsoleDriver { + protected Action TerminalResized; + /// /// The current number of columns in the terminal. /// @@ -323,6 +325,11 @@ namespace Terminal.Gui { /// Background color identifier. public abstract void SetColors (short foregroundColorId, short backgroundColorId); + public void SetTerminalResized(Action terminalResized) + { + TerminalResized = terminalResized; + } + /// /// Draws a frame on the specified region with the specified padding around the frame. /// diff --git a/Terminal.Gui/Drivers/CursesDriver.cs b/Terminal.Gui/Drivers/CursesDriver.cs index d63be806c..6697579b0 100644 --- a/Terminal.Gui/Drivers/CursesDriver.cs +++ b/Terminal.Gui/Drivers/CursesDriver.cs @@ -17,8 +17,6 @@ namespace Terminal.Gui { /// This is the Curses driver for the gui.cs/Terminal framework. /// public class CursesDriver : ConsoleDriver { - Action terminalResized; - public override int Cols => Curses.Cols; public override int Rows => Curses.Lines; @@ -159,7 +157,7 @@ namespace Terminal.Gui { if (code == Curses.KEY_CODE_YES) { if (wch == Curses.KeyResize) { if (Curses.CheckWinChange ()) { - terminalResized (); + TerminalResized?.Invoke (); return; } } @@ -226,7 +224,7 @@ namespace Terminal.Gui { Curses.Window.Standard.keypad (true); reportableMouseEvents = Curses.mousemask (Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents); - this.terminalResized = terminalResized; + TerminalResized = terminalResized; if (reportableMouseEvents.HasFlag (Curses.Event.ReportMousePosition)) StartReportingMouseMoves (); diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index 3143036b8..7304000e6 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -194,7 +194,7 @@ namespace Terminal.Gui { public override bool ProcessKey (KeyEvent kb) { var c = kb.KeyValue; - if (c == '\n' || c == ' ' || Rune.ToUpper ((Rune)c) == hot_key) { + if (c == '\n' || c == ' ' || Rune.ToUpper ((uint)c) == hot_key) { if (Clicked != null) Clicked (); return true;