From 2ef7ecaef9a9e53e2adb70c62df750e2eb13e330 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 8 Mar 2020 10:22:41 +0000 Subject: [PATCH 1/4] Fetch from upstream/master --- Designer/Designer.csproj | 2 +- Example/Example.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Designer/Designer.csproj b/Designer/Designer.csproj index e87bd0a6b..4374b4802 100644 --- a/Designer/Designer.csproj +++ b/Designer/Designer.csproj @@ -52,4 +52,4 @@ - + \ No newline at end of file diff --git a/Example/Example.csproj b/Example/Example.csproj index 3f6523667..95808f859 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -1,4 +1,4 @@ - + Debug @@ -52,4 +52,4 @@ - + \ No newline at end of file From a1c27554dbb1d6c1a16a35f4574814e937af715f Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 10 Mar 2020 00:49:10 +0000 Subject: [PATCH 2/4] Fixes #342 and improves color change interaction. Usage: Colors.Base.Normal = new Terminal.Gui.Attribute (Color.Green, Color.Black); --- .editorconfig | 3 + Terminal.Gui/Core.cs | 8 +- Terminal.Gui/Drivers/ConsoleDriver.cs | 154 ++++++++++++++++++++++++-- Terminal.Gui/Drivers/WindowsDriver.cs | 11 +- 4 files changed, 156 insertions(+), 20 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3ad2ee46d..576839082 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,3 +17,6 @@ csharp_preserve_single_line_blocks = true dotnet_style_require_accessibility_modifiers = never csharp_style_var_when_type_is_apparent = true csharp_prefer_braces = false +csharp_space_before_open_square_brackets = true +csharp_space_between_method_call_name_and_opening_parenthesis = true +csharp_space_between_method_declaration_name_and_open_parenthesis = true \ No newline at end of file diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index bc222f3a2..eebbf0f63 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -1585,9 +1585,9 @@ namespace Terminal.Gui { // a pending mouse event activated. if (true) return false; - + if ((mouseEvent.Flags == MouseFlags.Button1Pressed|| mouseEvent.Flags == MouseFlags.Button4Pressed)){ - + if (dragPosition.HasValue) { var dx = mouseEvent.X - dragPosition.Value.X; var dy = mouseEvent.Y - dragPosition.Value.Y; @@ -1741,7 +1741,7 @@ namespace Terminal.Gui { /// public static void Init () => Init (() => Toplevel.Create ()); - static bool _initialized = false; + internal static bool _initialized = false; /// /// Initializes the Application @@ -1749,7 +1749,6 @@ namespace Terminal.Gui { static void Init (Func topLevelFactory) { if (_initialized) return; - _initialized = true; var p = Environment.OSVersion.Platform; Mono.Terminal.IMainLoopDriver mainLoopDriver; @@ -1770,6 +1769,7 @@ namespace Terminal.Gui { SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext (MainLoop)); Top = topLevelFactory (); Current = Top; + _initialized = true; } /// diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs index 7ab4139f5..a09ca5fd8 100644 --- a/Terminal.Gui/Drivers/ConsoleDriver.cs +++ b/Terminal.Gui/Drivers/ConsoleDriver.cs @@ -6,6 +6,7 @@ // using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Mono.Terminal; using NStack; @@ -93,14 +94,27 @@ namespace Terminal.Gui { /// public struct Attribute { internal int value; + internal Color foreground; + internal Color background; /// /// Initializes a new instance of the struct. /// /// Value. - public Attribute (int value) + /// Foreground + /// Background + public Attribute (int value, Color foreground = new Color(), Color background = new Color()) { this.value = value; + this.foreground = foreground; + this.background = background; + } + + public Attribute (Color foreground = new Color (), Color background = new Color ()) + { + this.value = value = ((int)foreground | (int)background << 4); + this.foreground = foreground; + this.background = background; } /// @@ -137,50 +151,168 @@ namespace Terminal.Gui { /// views contained inside. /// public class ColorScheme { + private Attribute _normal; + private Attribute _focus; + private Attribute _hotNormal; + private Attribute _hotFocus; + /// /// The default color for text, when the view is not focused. /// - public Attribute Normal; + public Attribute Normal { get { return _normal; } set { _normal = SetColorScheme (value); } } + /// /// The color for text when the view has the focus. /// - public Attribute Focus; + public Attribute Focus { get { return _focus; } set { _focus = SetColorScheme (value); } } /// /// The color for the hotkey when a view is not focused /// - public Attribute HotNormal; + public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetColorScheme (value); } } /// /// The color for the hotkey when the view is focused. /// - public Attribute HotFocus; + public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetColorScheme (value); } } + + public string Caller = ""; + + private bool preparingScheme = false; + + private Attribute SetColorScheme (Attribute attribute, [CallerMemberName]string callerMemberName = null) + { + if (!Application._initialized && !preparingScheme) + return attribute; + + if (preparingScheme) + return attribute; + + preparingScheme = true; + switch (Caller) { + case "Base": + switch (callerMemberName) { + case "Normal": + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Menu": + switch (callerMemberName) { + case "Normal": + if (Focus.background != attribute.background) + Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background); + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + if (Focus.background != attribute.background) + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Dialog": + switch (callerMemberName) { + case "Normal": + if (Focus.background != attribute.background) + Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background); + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + if (Focus.background != attribute.background) + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + if (Normal.foreground != attribute.background) + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Error": + switch (callerMemberName) { + case "Normal": + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + case "HotFocus": + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, attribute.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + } + break; + + } + preparingScheme = false; + return attribute; + } } /// /// The default ColorSchemes for the application. /// public static class Colors { + private static ColorScheme _base; + private static ColorScheme _dialog; + private static ColorScheme _menu; + private static ColorScheme _error; + /// /// The base color scheme, for the default toplevel views. /// - public static ColorScheme Base; - + public static ColorScheme Base { get { return _base; } set { _base = SetColorScheme (value); } } + /// /// The dialog color scheme, for standard popup dialog boxes /// - public static ColorScheme Dialog; + public static ColorScheme Dialog { get { return _dialog; } set { _dialog = SetColorScheme (value); } } /// /// The menu bar color /// - public static ColorScheme Menu; + public static ColorScheme Menu { get { return _menu; } set { _menu = SetColorScheme (value); } } /// /// The color scheme for showing errors. /// - public static ColorScheme Error; + public static ColorScheme Error { get { return _error; } set { _error = SetColorScheme (value); } } + private static ColorScheme SetColorScheme (ColorScheme colorScheme, [CallerMemberName]string callerMemberName = null) + { + colorScheme.Caller = callerMemberName; + return colorScheme; + } } /// @@ -388,7 +520,7 @@ namespace Terminal.Gui { for (int l = 0; l < padding; l++) for (b = 0; b < width; b++) AddRune (' '); - } + } } diff --git a/Terminal.Gui/Drivers/WindowsDriver.cs b/Terminal.Gui/Drivers/WindowsDriver.cs index 0074181c7..31652f2ec 100644 --- a/Terminal.Gui/Drivers/WindowsDriver.cs +++ b/Terminal.Gui/Drivers/WindowsDriver.cs @@ -763,10 +763,10 @@ namespace Terminal.Gui { Colors.Base.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Blue); Colors.Base.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Cyan); - Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); + Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Cyan); Colors.Menu.Focus = MakeColor (ConsoleColor.White, ConsoleColor.Black); Colors.Menu.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Cyan); - Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Cyan); + Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); Colors.Dialog.Normal = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); Colors.Dialog.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Cyan); @@ -847,7 +847,9 @@ namespace Terminal.Gui { { // Encode the colors into the int value. return new Attribute () { - value = ((int)f | (int)b << 4) + value = ((int)f | (int)b << 4), + foreground = (Color)f, + background = (Color)b }; } @@ -881,7 +883,7 @@ namespace Terminal.Gui { { if (damageRegion.Left == -1) return; - + var bufferCoords = new WindowsConsole.Coord (){ X = (short)Clip.Width, Y = (short)Clip.Height @@ -945,5 +947,4 @@ namespace Terminal.Gui { } - } From 323183dafb99fcb2588b32117256edf5ecb4cae0 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 10 Mar 2020 02:10:59 +0000 Subject: [PATCH 3/4] Inserted new line at the end of file . Changed method name to SetAttribute in the ColorScheme class. --- Designer/Designer.csproj | 2 +- Example/Example.csproj | 2 +- Terminal.Gui/Drivers/ConsoleDriver.cs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Designer/Designer.csproj b/Designer/Designer.csproj index 4374b4802..e87bd0a6b 100644 --- a/Designer/Designer.csproj +++ b/Designer/Designer.csproj @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/Example/Example.csproj b/Example/Example.csproj index 95808f859..4bd86913e 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs index a09ca5fd8..684245cc6 100644 --- a/Terminal.Gui/Drivers/ConsoleDriver.cs +++ b/Terminal.Gui/Drivers/ConsoleDriver.cs @@ -159,28 +159,28 @@ namespace Terminal.Gui { /// /// The default color for text, when the view is not focused. /// - public Attribute Normal { get { return _normal; } set { _normal = SetColorScheme (value); } } + public Attribute Normal { get { return _normal; } set { _normal = SetAttribute (value); } } /// /// The color for text when the view has the focus. /// - public Attribute Focus { get { return _focus; } set { _focus = SetColorScheme (value); } } + public Attribute Focus { get { return _focus; } set { _focus = SetAttribute (value); } } /// /// The color for the hotkey when a view is not focused /// - public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetColorScheme (value); } } + public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetAttribute (value); } } /// /// The color for the hotkey when the view is focused. /// - public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetColorScheme (value); } } + public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetAttribute (value); } } public string Caller = ""; private bool preparingScheme = false; - private Attribute SetColorScheme (Attribute attribute, [CallerMemberName]string callerMemberName = null) + private Attribute SetAttribute (Attribute attribute, [CallerMemberName]string callerMemberName = null) { if (!Application._initialized && !preparingScheme) return attribute; From a4693558fd67d4963069345e21323d5c75af39b7 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Mon, 9 Mar 2020 14:30:15 -0400 Subject: [PATCH 4/4] Prepare for 0.70 --- Terminal.Gui/Terminal.Gui.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/Terminal.Gui.csproj b/Terminal.Gui/Terminal.Gui.csproj index 8dee18aa1..2f42588eb 100644 --- a/Terminal.Gui/Terminal.Gui.csproj +++ b/Terminal.Gui/Terminal.Gui.csproj @@ -9,7 +9,7 @@ true Terminal.Gui - 0.65 + 0.70 Miguel de Icaza MIT https://github.com/migueldeicaza/gui.cs/ @@ -18,7 +18,7 @@ Miguel de Icaza Application framework for creating modern console applications using .NET Gui.cs is a framework for creating console user interfaces - 0.25: Added new TimeField from Jörg Preiß; Fixes for Backtab by Martin Björkström; ListView now supports simple selection; Bug fixes by giladlevi, Daniel Cazzulino and Marius Ungureanu; New Application.Run of T entry point by Daniel Cazzulino; Added various View methods to bring forward, backwards and move views in the hierarchy; Switch to Portable PDBs by Daniel Cazzulino; Dims can now be compared by Daniel Cazzulino; OnMenuOpen handler by giladlevi; Various memory usage optimizations by giladlevi; FileDialog.FilePath is now a full path by Yanwei Wang; ISupportInitialize/ISupportInitializeNotification is now supported thanks to the work from Daniel Cazzulino; Support for non-modal TopLevels by Daniel Cazzulino and Adrian Alonso; 0.24: the Windows driver implements WakeUp, allowing some scenarios like bug #207 to be fixed; + 0.70: Bug fixes (320, 321, 306, 304, 291, 299, 303); Surface ListView.ListWrapper, surface various internal methods for use in ListView; Allow list item selection; ; 0.65: Added new TimeField from Jörg Preiß; Fixes for Backtab by Martin Björkström; ListView now supports simple selection; Bug fixes by giladlevi, Daniel Cazzulino and Marius Ungureanu; New Application.Run of T entry point by Daniel Cazzulino; Added various View methods to bring forward, backwards and move views in the hierarchy; Switch to Portable PDBs by Daniel Cazzulino; Dims can now be compared by Daniel Cazzulino; OnMenuOpen handler by giladlevi; Various memory usage optimizations by giladlevi; FileDialog.FilePath is now a full path by Yanwei Wang; ISupportInitialize/ISupportInitializeNotification is now supported thanks to the work from Daniel Cazzulino; Support for non-modal TopLevels by Daniel Cazzulino and Adrian Alonso; 0.24: the Windows driver implements WakeUp, allowing some scenarios like bug #207 to be fixed; 0.23: Better support for disabled menu items; Raises text changed event after the internals have been updated; Fix Caps-NumLock; Alt-HotKey now work on menus 0.22: Correct vertical scrollview behavior, Small curses driver fix for terminals without mouse support, TextView support for scrolling, Surface Used property on TextField, Surface Cursor on RadioGroup.