From bf35d8c44852694f6c6eb581179a0e43097c0bb2 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 9 Jun 2020 20:19:22 -0600 Subject: [PATCH 1/5] Added ConsoleDriver.GetFont and Windows' impl. --- .../CursesDriver/CursesDriver.cs | 7 ++- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 9 ++++ Terminal.Gui/ConsoleDrivers/NetDriver.cs | 5 +++ Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 45 ++++++++++++++++++- Terminal.Gui/Core/ConsoleDriver.cs | 27 +++++++++++ Terminal.Gui/Views/StatusBar.cs | 6 ++- UICatalog/UICatalog.cs | 8 +++- 7 files changed, 102 insertions(+), 5 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 6a133064b..170473b27 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -17,7 +17,6 @@ namespace Terminal.Gui { /// This is the Curses driver for the gui.cs/Terminal framework. /// internal class CursesDriver : ConsoleDriver { -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public override int Cols => Curses.Cols; public override int Rows => Curses.Lines; @@ -694,6 +693,11 @@ namespace Terminal.Gui { //mouseGrabbed = false; //Curses.mouseinterval (lastMouseInterval); } + + public override ConsoleFont GetFont () + { + return null; + } } internal static class Platform { @@ -755,7 +759,6 @@ namespace Terminal.Gui { killpg (0, signal); return true; } -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } } diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 19196397c..5b754d835 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -464,6 +464,15 @@ namespace Terminal.Gui { { } + /// + /// + /// + /// + public override ConsoleFont GetFont () + { + return null; + } + AutoResetEvent keyReady = new AutoResetEvent (false); AutoResetEvent waitForProbe = new AutoResetEvent (false); ConsoleKeyInfo? windowsKeyResult = null; diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index 91a39b3bf..b56a78af5 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -381,6 +381,11 @@ namespace Terminal.Gui { { } + public override ConsoleFont GetFont () + { + return null; + } + // // These are for the .NET driver, but running natively on Windows, wont run // on the Mono emulation diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 6397967e0..424c201fa 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -120,6 +120,27 @@ namespace Terminal.Gui { } } + public ConsoleDriver.ConsoleFont GetFont () + { + ConsoleDriver.ConsoleFont cf = null; + CONSOLE_FONT_INFO_EX fontInfoEx = new CONSOLE_FONT_INFO_EX (); + fontInfoEx.cbSize = Marshal.SizeOf (typeof (CONSOLE_FONT_INFO_EX)); + + if (GetCurrentConsoleFontEx(OutputHandle, false, ref fontInfoEx)) { + cf = new ConsoleDriver.ConsoleFont (); + cf.FaceName = fontInfoEx.FaceName; + cf.Size = new Size (fontInfoEx.FontWidth, fontInfoEx.FontHeight); + cf.Weight = fontInfoEx.FontWeight; + } + + var err = Marshal.GetLastWin32Error (); + if (err != 0) + throw new System.ComponentModel.Win32Exception (err); + + return cf; + + } + [Flags] public enum ConsoleModes : uint { EnableProcessedInput = 1, @@ -420,6 +441,24 @@ namespace Terminal.Gui { return v; } } + + [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct CONSOLE_FONT_INFO_EX { + public int cbSize; + public int FontIndex; + public short FontWidth; + public short FontHeight; + public int FontFamily; + public int FontWeight; + [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 32)] + public string FaceName; + } + + [DllImport ("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + extern static bool GetCurrentConsoleFontEx ( + IntPtr hConsoleOutput, + bool bMaximumWindow, + [In,Out] ref CONSOLE_FONT_INFO_EX lpConsoleCurrentFont); } internal class WindowsDriver : ConsoleDriver, IMainLoopDriver { @@ -1265,8 +1304,12 @@ namespace Terminal.Gui { public override void CookMouse () { } - #endregion + public override ConsoleFont GetFont () + { + return winConsole.GetFont (); + } + #endregion } } diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index 77f61f1e2..8495b42fc 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -8,6 +8,7 @@ using NStack; using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; @@ -888,6 +889,12 @@ namespace Terminal.Gui { /// public abstract void CookMouse (); + /// + /// Gets the current font set for the console. + /// + /// The Font for the current console. null if the console driver does not support querying the font. + public abstract ConsoleFont GetFont (); + /// /// Horizontal line character. /// @@ -1025,5 +1032,25 @@ namespace Terminal.Gui { /// Background. /// public abstract Attribute MakeAttribute (Color fore, Color back); + + /// + /// Contains information for a console font. + /// + public class ConsoleFont { + /// + /// The name of the typeface (such as Courier or Arial). + /// + public string FaceName; + + /// + /// The font weight. The weight can range from 100 to 1000, in multiples of 100. For example, the normal weight is 400, while 700 is bold. + /// + public int Weight; + + /// + /// Contains the width and height of each character in the font, in logical units. The X member contains the width, while the Y member contains the height. + /// + public Size Size; + } } } diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index baf44035f..6bb3ca967 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -181,7 +181,11 @@ namespace Terminal.Gui { } Driver.AddRune (title [n]); } - Driver.AddRune (' '); + if (i + 1 < Items.Length) { + Driver.AddRune (' '); + Driver.AddRune (Driver.VLine); + Driver.AddRune (' '); + } } } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index c90f64e46..c5b26a32c 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -266,6 +266,11 @@ namespace UICatalog { _numlock = new StatusItem (Key.CharMask, "Numlock", null); _scrolllock = new StatusItem (Key.CharMask, "Scrolllock", null); + ConsoleDriver.ConsoleFont consoleFont = Application.Driver.GetFont (); + StatusItem font = new StatusItem (Key.Unknown, $"Console driver does not support querying font.", null); ; + if (consoleFont != null) { + font = new StatusItem (Key.Unknown, $"Console Font: {consoleFont.FaceName}, {consoleFont.Weight}, {consoleFont.Size.Width}x{consoleFont.Size.Height}", null); + } _statusBar = new StatusBar (new StatusItem [] { new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => { if (_runningScenario is null){ @@ -278,7 +283,8 @@ namespace UICatalog { }), _capslock, _numlock, - _scrolllock + _scrolllock, + font }); SetColorScheme (); From 9d39c1f1871fa45df485bac9b90ec95753fd8e7d Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 9 Jun 2020 20:30:18 -0600 Subject: [PATCH 2/5] moved fns --- Terminal.Gui/Core/ConsoleDriver.cs | 40 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index 8495b42fc..8548fe86d 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -889,6 +889,26 @@ namespace Terminal.Gui { /// public abstract void CookMouse (); + /// + /// Contains information for a console font. + /// + public class ConsoleFont { + /// + /// The name of the typeface (such as Courier or Arial). + /// + public string FaceName; + + /// + /// The font weight. The weight can range from 100 to 1000, in multiples of 100. For example, the normal weight is 400, while 700 is bold. + /// + public int Weight; + + /// + /// Contains the width and height of each character in the font, in logical units. The X member contains the width, while the Y member contains the height. + /// + public Size Size; + } + /// /// Gets the current font set for the console. /// @@ -1032,25 +1052,5 @@ namespace Terminal.Gui { /// Background. /// public abstract Attribute MakeAttribute (Color fore, Color back); - - /// - /// Contains information for a console font. - /// - public class ConsoleFont { - /// - /// The name of the typeface (such as Courier or Arial). - /// - public string FaceName; - - /// - /// The font weight. The weight can range from 100 to 1000, in multiples of 100. For example, the normal weight is 400, while 700 is bold. - /// - public int Weight; - - /// - /// Contains the width and height of each character in the font, in logical units. The X member contains the width, while the Y member contains the height. - /// - public Size Size; - } } } From da505a7c3da39f1c1954ab0a029174799ba7d62e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 9 Jun 2020 20:34:27 -0600 Subject: [PATCH 3/5] removed status bar vline change --- Terminal.Gui/Views/StatusBar.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 6bb3ca967..baf44035f 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -181,11 +181,7 @@ namespace Terminal.Gui { } Driver.AddRune (title [n]); } - if (i + 1 < Items.Length) { - Driver.AddRune (' '); - Driver.AddRune (Driver.VLine); - Driver.AddRune (' '); - } + Driver.AddRune (' '); } } From cdf6d85e596e9a73cda3dbc0c269019c0f43fa51 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 15 Jun 2020 12:31:06 -0700 Subject: [PATCH 4/5] Revert "refactored consoledriver for more reuse" This reverts commit 3948d9c554d1431d52944d39628d916f071d04d8, reversing changes made to c02054d01ce01aa8e50856c95e7ca6d43dc6e810. --- .../CursesDriver/CursesDriver.cs | 70 ++- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 63 ++- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 94 ++-- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 125 ++++-- Terminal.Gui/Core/ConsoleDriver.cs | 421 ++++++++---------- Terminal.Gui/Core/Window.cs | 1 + Terminal.Gui/Views/Button.cs | 8 +- Terminal.Gui/Views/Menu.cs | 16 +- Terminal.Gui/Views/ProgressBar.cs | 4 +- Terminal.Gui/Views/RadioGroup.cs | 2 +- Terminal.Gui/Views/ScrollView.cs | 40 +- Terminal.Gui/Views/StatusBar.cs | 2 +- UICatalog/UICatalog.cs | 5 - 13 files changed, 438 insertions(+), 413 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index f018edce4..98faa32ac 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -17,6 +17,7 @@ namespace Terminal.Gui { /// This is the Curses driver for the gui.cs/Terminal framework. /// internal class CursesDriver : ConsoleDriver { +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public override int Cols => Curses.Cols; public override int Rows => Curses.Lines; @@ -66,8 +67,7 @@ namespace Terminal.Gui { AddRune (rune); } - public override void Refresh () - { + public override void Refresh () { Curses.refresh (); if (Curses.CheckWinChange ()) { TerminalResized?.Invoke (); @@ -270,7 +270,8 @@ namespace Terminal.Gui { mouseFlag = MouseFlags.WheeledDown; canWheeledDown = true; - } else if (cev.ButtonState == Curses.Event.ReportMousePosition && !canWheeledDown) { + } + else if (cev.ButtonState == Curses.Event.ReportMousePosition && !canWheeledDown) { mouseFlag = MouseFlags.ReportMousePosition; canWheeledDown = true; @@ -518,32 +519,32 @@ namespace Terminal.Gui { if (reportableMouseEvents.HasFlag (Curses.Event.ReportMousePosition)) StartReportingMouseMoves (); - Glyphs.HLine = Curses.ACS_HLINE; - Glyphs.VLine = Curses.ACS_VLINE; - Glyphs.Stipple = Curses.ACS_CKBOARD; - Glyphs.Diamond = Curses.ACS_DIAMOND; - Glyphs.ULCorner = Curses.ACS_ULCORNER; - Glyphs.LLCorner = Curses.ACS_LLCORNER; - Glyphs.URCorner = Curses.ACS_URCORNER; - Glyphs.LRCorner = Curses.ACS_LRCORNER; - Glyphs.LeftTee = Curses.ACS_LTEE; - Glyphs.RightTee = Curses.ACS_RTEE; - Glyphs.TopTee = Curses.ACS_TTEE; - Glyphs.BottomTee = Curses.ACS_BTEE; - Glyphs.Checked = '\u221a'; - Glyphs.UnChecked = ' '; - Glyphs.Selected = '\u25cf'; - Glyphs.UnSelected = '\u25cc'; - Glyphs.RightArrow = Curses.ACS_RARROW; - Glyphs.LeftArrow = Curses.ACS_LARROW; - Glyphs.UpArrow = Curses.ACS_UARROW; - Glyphs.DownArrow = Curses.ACS_DARROW; - Glyphs.LeftDefaultIndicator = '\u25e6'; - Glyphs.RightDefaultIndicator = '\u25e6'; - Glyphs.LeftBracket = '['; - Glyphs.RightBracket = ']'; - Glyphs.OnMeterSegment = '\u258c'; - Glyphs.OffMeterSegement = ' '; + HLine = Curses.ACS_HLINE; + VLine = Curses.ACS_VLINE; + Stipple = Curses.ACS_CKBOARD; + Diamond = Curses.ACS_DIAMOND; + ULCorner = Curses.ACS_ULCORNER; + LLCorner = Curses.ACS_LLCORNER; + URCorner = Curses.ACS_URCORNER; + LRCorner = Curses.ACS_LRCORNER; + LeftTee = Curses.ACS_LTEE; + RightTee = Curses.ACS_RTEE; + TopTee = Curses.ACS_TTEE; + BottomTee = Curses.ACS_BTEE; + Checked = '\u221a'; + UnChecked = ' '; + Selected = '\u25cf'; + UnSelected = '\u25cc'; + RightArrow = Curses.ACS_RARROW; + LeftArrow = Curses.ACS_LARROW; + UpArrow = Curses.ACS_UARROW; + DownArrow = Curses.ACS_DARROW; + LeftDefaultIndicator = '\u25e6'; + RightDefaultIndicator = '\u25e6'; + LeftBracket = '['; + RightBracket = ']'; + OnMeterSegment = '\u258c'; + OffMeterSegement = ' '; Colors.TopLevel = new ColorScheme (); Colors.Base = new ColorScheme (); @@ -693,16 +694,6 @@ namespace Terminal.Gui { //mouseGrabbed = false; //Curses.mouseinterval (lastMouseInterval); } - - public override ConsoleFont GetFont () - { - return null; - } - - public override Capabilites GetCapabilites () - { - throw new NotImplementedException (); - } } internal static class Platform { @@ -764,6 +755,7 @@ namespace Terminal.Gui { killpg (0, signal); return true; } +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } } diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index e651c896a..85faaf25f 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -84,7 +84,10 @@ namespace Terminal.Gui { } - /// + /// + /// + /// + /// public override void AddRune (Rune rune) { if (Clip.Contains (ccol, crow)) { @@ -109,28 +112,35 @@ namespace Terminal.Gui { UpdateScreen (); } - /// + /// + /// + /// + /// public override void AddStr (ustring str) { foreach (var rune in str) AddRune (rune); } - /// + /// + /// + /// public override void End () { FakeConsole.ResetColor (); FakeConsole.Clear (); } - /// - public override Attribute MakeColor (ConsoleColor f, ConsoleColor b) + static Attribute MakeColor (ConsoleColor f, ConsoleColor b) { // Encode the colors into the int value. return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) }; } - /// + /// + /// + /// + /// public override void Init (Action terminalResized) { Colors.TopLevel = new ColorScheme (); @@ -170,6 +180,35 @@ namespace Terminal.Gui { Colors.Error.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); Colors.Error.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Red); Colors.Error.HotFocus = Colors.Error.HotNormal; + + HLine = '\u2500'; + VLine = '\u2502'; + Stipple = '\u2592'; + Diamond = '\u25c6'; + ULCorner = '\u250C'; + LLCorner = '\u2514'; + URCorner = '\u2510'; + LRCorner = '\u2518'; + LeftTee = '\u251c'; + RightTee = '\u2524'; + TopTee = '\u22a4'; + BottomTee = '\u22a5'; + Checked = '\u221a'; + UnChecked = ' '; + Selected = '\u25cf'; + UnSelected = '\u25cc'; + RightArrow = '\u25ba'; + LeftArrow = '\u25c4'; + UpArrow = '\u25b2'; + DownArrow = '\u25bc'; + LeftDefaultIndicator = '\u25e6'; + RightDefaultIndicator = '\u25e6'; + LeftBracket = '['; + RightBracket = ']'; + OnMeterSegment = '\u258c'; + OffMeterSegement = ' '; + + //MockConsole.Clear (); } /// @@ -424,17 +463,5 @@ namespace Terminal.Gui { public override void UncookMouse () { } - - /// - public override ConsoleFont GetFont () - { - return null; - } - - /// - public override Capabilites GetCapabilites () - { - throw new NotImplementedException (); - } } } \ No newline at end of file diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index abb69fec2..c7317d30d 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -43,20 +43,11 @@ namespace Terminal.Gui { public NetDriver () { - Glyphs.LeftDefaultIndicator = '<'; - Glyphs.RightDefaultIndicator = '>'; - cols = Console.WindowWidth; rows = Console.WindowHeight - 1; UpdateOffscreen (); } - public override Attribute MakeColor (ConsoleColor f, ConsoleColor b) - { - // Encode the colors into the int value. - return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) }; - } - bool needMove; // Current row, and current col, tracked by Move/AddCh only int ccol, crow; @@ -113,18 +104,80 @@ namespace Terminal.Gui { Console.Clear (); } - //public override Attribute MakeColor (ConsoleColor f, ConsoleColor b) - //{ - // // Encode the colors into the int value. - // return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) }; - //} + static Attribute MakeColor (ConsoleColor f, ConsoleColor b) + { + // Encode the colors into the int value. + return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) }; + } public override void Init (Action terminalResized) { + Colors.TopLevel = new ColorScheme (); + Colors.Base = new ColorScheme (); + Colors.Dialog = new ColorScheme (); + Colors.Menu = new ColorScheme (); + Colors.Error = new ColorScheme (); Clip = new Rect (0, 0, Cols, Rows); + Colors.TopLevel.Normal = MakeColor (ConsoleColor.Green, ConsoleColor.Black); + Colors.TopLevel.Focus = MakeColor (ConsoleColor.White, ConsoleColor.DarkCyan); + Colors.TopLevel.HotNormal = MakeColor (ConsoleColor.DarkYellow, ConsoleColor.Black); + Colors.TopLevel.HotFocus = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.DarkCyan); + + Colors.Base.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Blue); + Colors.Base.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Cyan); + Colors.Base.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Blue); + Colors.Base.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Cyan); + + // Focused, + // Selected, Hot: Yellow on Black + // Selected, text: white on black + // Unselected, hot: yellow on cyan + // unselected, text: same as unfocused + Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); + 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.Disabled = MakeColor (ConsoleColor.DarkGray, ConsoleColor.Cyan); + + Colors.Dialog.Normal = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); + Colors.Dialog.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Cyan); + Colors.Dialog.HotNormal = MakeColor (ConsoleColor.Blue, ConsoleColor.Gray); + Colors.Dialog.HotFocus = MakeColor (ConsoleColor.Blue, ConsoleColor.Cyan); + + Colors.Error.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Red); + Colors.Error.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); + Colors.Error.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Red); + Colors.Error.HotFocus = Colors.Error.HotNormal; Console.Clear (); + + HLine = '\u2500'; + VLine = '\u2502'; + Stipple = '\u2592'; + Diamond = '\u25c6'; + ULCorner = '\u250C'; + LLCorner = '\u2514'; + URCorner = '\u2510'; + LRCorner = '\u2518'; + LeftTee = '\u251c'; + RightTee = '\u2524'; + TopTee = '\u22a4'; + BottomTee = '\u22a5'; + Checked = '\u221a'; + UnChecked = ' '; + Selected = '\u25cf'; + UnSelected = '\u25cc'; + RightArrow = '\u25ba'; + LeftArrow = '\u25c4'; + UpArrow = '\u25b2'; + DownArrow = '\u25bc'; + LeftDefaultIndicator = '\u25e6'; + RightDefaultIndicator = '\u25e6'; + LeftBracket = '['; + RightBracket = ']'; + OnMeterSegment = '\u258c'; + OffMeterSegement = ' '; } public override Attribute MakeAttribute (Color fore, Color back) @@ -199,6 +252,7 @@ namespace Terminal.Gui { public override void UpdateCursor () { + // } public override void StartReportingMouseMoves () @@ -327,16 +381,6 @@ namespace Terminal.Gui { { } - public override ConsoleFont GetFont () - { - return null; - } - - public override Capabilites GetCapabilites () - { - throw new NotImplementedException (); - } - // // These are for the .NET driver, but running natively on Windows, wont run // on the Mono emulation @@ -383,7 +427,7 @@ namespace Terminal.Gui { { while (true) { waitForProbe.WaitOne (); - keyResult = consoleKeyReaderFn (); + keyResult = consoleKeyReaderFn(); keyReady.Set (); } } diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index c536a9bfc..1cb899067 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -120,27 +120,6 @@ namespace Terminal.Gui { } } - public ConsoleDriver.ConsoleFont GetFont () - { - ConsoleDriver.ConsoleFont cf = null; - CONSOLE_FONT_INFO_EX fontInfoEx = new CONSOLE_FONT_INFO_EX (); - fontInfoEx.cbSize = Marshal.SizeOf (typeof (CONSOLE_FONT_INFO_EX)); - - if (GetCurrentConsoleFontEx(OutputHandle, false, ref fontInfoEx)) { - cf = new ConsoleDriver.ConsoleFont (); - cf.FaceName = fontInfoEx.FaceName; - cf.Size = new Size (fontInfoEx.FontWidth, fontInfoEx.FontHeight); - cf.Weight = fontInfoEx.FontWeight; - } - - var err = Marshal.GetLastWin32Error (); - if (err != 0) - throw new System.ComponentModel.Win32Exception (err); - - return cf; - - } - [Flags] public enum ConsoleModes : uint { EnableProcessedInput = 1, @@ -482,24 +461,6 @@ namespace Terminal.Gui { consoleScreenBufferInfo.srWindow.Bottom - consoleScreenBufferInfo.srWindow.Top); } #endif - - [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode)] - public struct CONSOLE_FONT_INFO_EX { - public int cbSize; - public int FontIndex; - public short FontWidth; - public short FontHeight; - public int FontFamily; - public int FontWeight; - [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 32)] - public string FaceName; - } - - [DllImport ("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - extern static bool GetCurrentConsoleFontEx ( - IntPtr hConsoleOutput, - bool bMaximumWindow, - [In,Out] ref CONSOLE_FONT_INFO_EX lpConsoleCurrentFont); } internal class WindowsDriver : ConsoleDriver, IMainLoopDriver { @@ -519,6 +480,8 @@ namespace Terminal.Gui { { winConsole = new WindowsConsole (); + SetupColorsAndBorders (); + cols = Console.WindowWidth; rows = Console.WindowHeight; WindowsConsole.SmallRect.MakeEmpty (ref damageRegion); @@ -529,6 +492,68 @@ namespace Terminal.Gui { Task.Run ((Action)WindowsInputHandler); } + private void SetupColorsAndBorders () + { + Colors.TopLevel = new ColorScheme (); + Colors.Base = new ColorScheme (); + Colors.Dialog = new ColorScheme (); + Colors.Menu = new ColorScheme (); + Colors.Error = new ColorScheme (); + + Colors.TopLevel.Normal = MakeColor (ConsoleColor.Green, ConsoleColor.Black); + Colors.TopLevel.Focus = MakeColor (ConsoleColor.White, ConsoleColor.DarkCyan); + Colors.TopLevel.HotNormal = MakeColor (ConsoleColor.DarkYellow, ConsoleColor.Black); + Colors.TopLevel.HotFocus = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.DarkCyan); + + Colors.Base.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkBlue); + Colors.Base.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); + Colors.Base.HotNormal = MakeColor (ConsoleColor.DarkCyan, ConsoleColor.DarkBlue); + Colors.Base.HotFocus = MakeColor (ConsoleColor.Blue, ConsoleColor.Gray); + + Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkGray); + Colors.Menu.Focus = MakeColor (ConsoleColor.White, ConsoleColor.Black); + Colors.Menu.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.DarkGray); + Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); + Colors.Menu.Disabled = MakeColor (ConsoleColor.Gray, ConsoleColor.DarkGray); + + Colors.Dialog.Normal = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); + Colors.Dialog.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.DarkGray); + Colors.Dialog.HotNormal = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.Gray); + Colors.Dialog.HotFocus = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.DarkGray); + + Colors.Error.Normal = MakeColor (ConsoleColor.DarkRed, ConsoleColor.White); + Colors.Error.Focus = MakeColor (ConsoleColor.White, ConsoleColor.DarkRed); + Colors.Error.HotNormal = MakeColor (ConsoleColor.Black, ConsoleColor.White); + Colors.Error.HotFocus = MakeColor (ConsoleColor.Black, ConsoleColor.DarkRed); + + HLine = '\u2500'; + VLine = '\u2502'; + Stipple = '\u2591'; + Diamond = '\u25ca'; + ULCorner = '\u250C'; + LLCorner = '\u2514'; + URCorner = '\u2510'; + LRCorner = '\u2518'; + LeftTee = '\u251c'; + RightTee = '\u2524'; + TopTee = '\u252c'; + BottomTee = '\u2534'; + Checked = '\u221a'; + UnChecked = ' '; + Selected = '\u25cf'; + UnSelected = '\u25cc'; + RightArrow = '\u25ba'; + LeftArrow = '\u25c4'; + UpArrow = '\u25b2'; + DownArrow = '\u25bc'; + LeftDefaultIndicator = '\u25e6'; + RightDefaultIndicator = '\u25e6'; + LeftBracket = '['; + RightBracket = ']'; + OnMeterSegment = '\u258c'; + OffMeterSegement = ' '; + } + [StructLayout (LayoutKind.Sequential)] public struct ConsoleKeyInfoEx { public ConsoleKeyInfo consoleKeyInfo; @@ -1123,6 +1148,7 @@ namespace Terminal.Gui { public override void Init (Action terminalResized) { TerminalResized = terminalResized; + SetupColorsAndBorders (); } void ResizeScreen () @@ -1194,6 +1220,16 @@ namespace Terminal.Gui { currentAttribute = c.value; } + Attribute MakeColor (ConsoleColor f, ConsoleColor b) + { + // Encode the colors into the int value. + return new Attribute () { + value = ((int)f | (int)b << 4), + foreground = (Color)f, + background = (Color)b + }; + } + public override Attribute MakeAttribute (Color fore, Color back) { return MakeColor ((ConsoleColor)fore, (ConsoleColor)back); @@ -1285,17 +1321,8 @@ namespace Terminal.Gui { public override void CookMouse () { } - public override ConsoleFont GetFont () - { - return winConsole.GetFont (); - - } - - public override Capabilites GetCapabilites () - { - throw new NotImplementedException (); - } #endregion + } } diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index ee6de23a2..77f61f1e2 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -8,7 +8,6 @@ using NStack; using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; @@ -459,225 +458,76 @@ namespace Terminal.Gui { public static Dictionary ColorSchemes { get; } } - /// - /// Provides glyphs used for drawning standard UI elements such as frames and buttons. - /// - public static class Glyphs { - /// - /// Horizontal line character. - /// - public static Rune HLine; + ///// + ///// Special characters that can be drawn with + ///// + //public enum SpecialChar { + // /// + // /// Horizontal line character. + // /// + // HLine, - /// - /// Vertical line character. - /// - public static Rune VLine; + // /// + // /// Vertical line character. + // /// + // VLine, - /// - /// Stipple pattern - /// - public static Rune Stipple; + // /// + // /// Stipple pattern + // /// + // Stipple, - /// - /// Diamond character - /// - public static Rune Diamond; + // /// + // /// Diamond character + // /// + // Diamond, - /// - /// Upper left corner - /// - public static Rune ULCorner; + // /// + // /// Upper left corner + // /// + // ULCorner, - /// - /// Lower left corner - /// - public static Rune LLCorner; + // /// + // /// Lower left corner + // /// + // LLCorner, - /// - /// Upper right corner - /// - public static Rune URCorner; + // /// + // /// Upper right corner + // /// + // URCorner, - /// - /// Lower right corner - /// - public static Rune LRCorner; + // /// + // /// Lower right corner + // /// + // LRCorner, - /// - /// Left tee - /// - public static Rune LeftTee; + // /// + // /// Left tee + // /// + // LeftTee, - /// - /// Right tee - /// - public static Rune RightTee; + // /// + // /// Right tee + // /// + // RightTee, - /// - /// Top tee - /// - public static Rune TopTee; + // /// + // /// Top tee + // /// + // TopTee, - /// - /// The bottom tee. - /// - public static Rune BottomTee; - - /// - /// Checkmark. - /// - public static Rune Checked; - - /// - /// Un-checked checkmark. - /// - public static Rune UnChecked; - - /// - /// Selected mark. - /// - public static Rune Selected; - - /// - /// Un-selected selected mark. - /// - public static Rune UnSelected; - - /// - /// Right Arrow. - /// - public static Rune RightArrow; - - /// - /// Left Arrow. - /// - public static Rune LeftArrow; - - /// - /// Down Arrow. - /// - public static Rune DownArrow; - - /// - /// Up Arrow. - /// - public static Rune UpArrow; - - /// - /// Left indicator for default action (e.g. for ). - /// - public static Rune LeftDefaultIndicator; - - /// - /// Right indicator for default action (e.g. for ). - /// - public static Rune RightDefaultIndicator; - - /// - /// Left frame/bracket (e.g. '[' for ). - /// - public static Rune LeftBracket; - - /// - /// Right frame/bracket (e.g. ']' for ). - /// - public static Rune RightBracket; - - /// - /// On Segment indicator for meter views (e.g. . - /// - public static Rune OnMeterSegment; - - /// - /// Off Segment indicator for meter views (e.g. . - /// - public static Rune OffMeterSegement; - } + // /// + // /// The bottom tee. + // /// + // BottomTee, + //} /// /// ConsoleDriver is an abstract class that defines the requirements for a console driver. /// There are currently three implementations: (for Unix and Mac), , and that uses the .NET Console API. /// public abstract class ConsoleDriver { - - /// - /// Initalizes a new object. Sets default colors and common glyphs. - /// - public ConsoleDriver () - { - Colors.TopLevel = new ColorScheme (); - Colors.Base = new ColorScheme (); - Colors.Dialog = new ColorScheme (); - Colors.Menu = new ColorScheme (); - Colors.Error = new ColorScheme (); - - Colors.TopLevel.Normal = MakeColor (ConsoleColor.Green, ConsoleColor.Black); - Colors.TopLevel.Focus = MakeColor (ConsoleColor.White, ConsoleColor.DarkCyan); - Colors.TopLevel.HotNormal = MakeColor (ConsoleColor.DarkYellow, ConsoleColor.Black); - Colors.TopLevel.HotFocus = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.DarkCyan); - - Colors.Base.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkBlue); - Colors.Base.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); - Colors.Base.HotNormal = MakeColor (ConsoleColor.DarkCyan, ConsoleColor.DarkBlue); - Colors.Base.HotFocus = MakeColor (ConsoleColor.Blue, ConsoleColor.Gray); - - Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.DarkGray); - Colors.Menu.Focus = MakeColor (ConsoleColor.White, ConsoleColor.Black); - Colors.Menu.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.DarkGray); - Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); - Colors.Menu.Disabled = MakeColor (ConsoleColor.Gray, ConsoleColor.DarkGray); - - Colors.Dialog.Normal = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); - Colors.Dialog.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.DarkGray); - Colors.Dialog.HotNormal = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.Gray); - Colors.Dialog.HotFocus = MakeColor (ConsoleColor.DarkBlue, ConsoleColor.DarkGray); - - Colors.Error.Normal = MakeColor (ConsoleColor.DarkRed, ConsoleColor.White); - Colors.Error.Focus = MakeColor (ConsoleColor.White, ConsoleColor.DarkRed); - Colors.Error.HotNormal = MakeColor (ConsoleColor.Black, ConsoleColor.White); - Colors.Error.HotFocus = MakeColor (ConsoleColor.Black, ConsoleColor.DarkRed); - - Glyphs.HLine = '\u2500'; - Glyphs.VLine = '\u2502'; - Glyphs.Stipple = '\u2592'; - Glyphs.Diamond = '\u25c6'; - Glyphs.ULCorner = '\u250C'; - Glyphs.LLCorner = '\u2514'; - Glyphs.URCorner = '\u2510'; - Glyphs.LRCorner = '\u2518'; - Glyphs.LeftTee = '\u251c'; - Glyphs.RightTee = '\u2524'; - Glyphs.TopTee = '\u22a4'; - Glyphs.BottomTee = '\u22a5'; - Glyphs.Checked = '\u221a'; - Glyphs.UnChecked = ' '; - Glyphs.Selected = '\u25cf'; - Glyphs.UnSelected = '\u25cc'; - Glyphs.RightArrow = '\u25ba'; - Glyphs.LeftArrow = '\u25c4'; - Glyphs.UpArrow = '\u25b2'; - Glyphs.DownArrow = '\u25bc'; - Glyphs.LeftDefaultIndicator = '\u25e6'; - Glyphs.RightDefaultIndicator = '\u25e6'; - Glyphs.LeftBracket = '['; - Glyphs.RightBracket = ']'; - Glyphs.OnMeterSegment = '\u258c'; - Glyphs.OffMeterSegement = ' '; - } - - /// - /// Creates an Attribute based on a forground and background color - /// - public virtual Attribute MakeColor (ConsoleColor foregroundColor, ConsoleColor backgroundColor) - { - // Encode the colors into the int value. - return new Attribute () { - value = ((int)foregroundColor | (int)backgroundColor << 4), - foreground = (Color)foregroundColor, - background = (Color)backgroundColor - }; - } - /// /// The handler fired when the terminal is resized. /// @@ -755,6 +605,8 @@ namespace Terminal.Gui { /// Background. public abstract void SetColors (ConsoleColor foreground, ConsoleColor background); + // Advanced uses - set colors to any pre-set pairs, you would need to init_color + // that independently with the R, G, B values. /// /// Advanced uses - set colors to any pre-set pairs, you would need to init_color /// that independently with the R, G, B values. @@ -871,12 +723,12 @@ namespace Terminal.Gui { // fbottom is locaiton of bottom frame line int fbottom = ftop + fheight + 1; - Rune hLine = border ? Glyphs.HLine : clearChar; - Rune vLine = border ? Glyphs.VLine : clearChar; - Rune uRCorner = border ? Glyphs.URCorner : clearChar; - Rune uLCorner = border ? Glyphs.ULCorner : clearChar; - Rune lLCorner = border ? Glyphs.LLCorner : clearChar; - Rune lRCorner = border ? Glyphs.LRCorner : clearChar; + Rune hLine = border ? HLine : clearChar; + Rune vLine = border ? VLine : clearChar; + Rune uRCorner = border ? URCorner : clearChar; + Rune uLCorner = border ? ULCorner : clearChar; + Rune lLCorner = border ? LLCorner : clearChar; + Rune lRCorner = border ? LRCorner : clearChar; // Outside top if (paddingTop > 1) { @@ -1037,48 +889,135 @@ namespace Terminal.Gui { public abstract void CookMouse (); /// - /// Defines the capabilities of the Console. + /// Horizontal line character. /// - public class Capabilites { - /// - /// If true the Console supports Unicode. If false the Console cannot render - /// Unicode characters properly. - /// - public bool Unicode { get; set; } - } + public Rune HLine; /// - /// Returns the capabilities of the console. + /// Vertical line character. /// - /// The console's capabilities - public abstract Capabilites GetCapabilites (); + public Rune VLine; /// - /// Contains information for a console font. + /// Stipple pattern /// - public class ConsoleFont { - /// - /// The name of the typeface (such as Courier or Arial). - /// - public string FaceName; - - /// - /// The font weight. The weight can range from 100 to 1000, in multiples of 100. For example, the normal weight is 400, while 700 is bold. - /// - public int Weight; - - /// - /// Contains the width and height of each character in the font, in logical units. The X member contains the width, while the Y member contains the height. - /// - public Size Size; - } + public Rune Stipple; /// - /// Gets the current font set for the console. + /// Diamond character /// - /// The Font for the current console. null if the console driver does not support querying the font. - public abstract ConsoleFont GetFont (); - + public Rune Diamond; + + /// + /// Upper left corner + /// + public Rune ULCorner; + + /// + /// Lower left corner + /// + public Rune LLCorner; + + /// + /// Upper right corner + /// + public Rune URCorner; + + /// + /// Lower right corner + /// + public Rune LRCorner; + + /// + /// Left tee + /// + public Rune LeftTee; + + /// + /// Right tee + /// + public Rune RightTee; + + /// + /// Top tee + /// + public Rune TopTee; + + /// + /// The bottom tee. + /// + public Rune BottomTee; + + /// + /// Checkmark. + /// + public Rune Checked; + + /// + /// Un-checked checkmark. + /// + public Rune UnChecked; + + /// + /// Selected mark. + /// + public Rune Selected; + + /// + /// Un-selected selected mark. + /// + public Rune UnSelected; + + /// + /// Right Arrow. + /// + public Rune RightArrow; + + /// + /// Left Arrow. + /// + public Rune LeftArrow; + + /// + /// Down Arrow. + /// + public Rune DownArrow; + + /// + /// Up Arrow. + /// + public Rune UpArrow; + + /// + /// Left indicator for default action (e.g. for ). + /// + public Rune LeftDefaultIndicator; + + /// + /// Right indicator for default action (e.g. for ). + /// + public Rune RightDefaultIndicator; + + /// + /// Left frame/bracket (e.g. '[' for ). + /// + public Rune LeftBracket; + + /// + /// Right frame/bracket (e.g. ']' for ). + /// + public Rune RightBracket; + + /// + /// On Segment indicator for meter views (e.g. . + /// + public Rune OnMeterSegment; + + /// + /// Off Segment indicator for meter views (e.g. . + /// + public Rune OffMeterSegement; + /// /// Make the attribute for the foreground and background colors. /// diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index 1afa6afdf..1cd4be592 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -29,6 +29,7 @@ namespace Terminal.Gui { } } + /// /// ContentView is an internal implementation detail of Window. It is used to host Views added with . /// Its ONLY reason for being is to provide a simple way for Window to expose to those SubViews that the Window's Bounds diff --git a/Terminal.Gui/Views/Button.cs b/Terminal.Gui/Views/Button.cs index f7a15223b..36b848544 100644 --- a/Terminal.Gui/Views/Button.cs +++ b/Terminal.Gui/Views/Button.cs @@ -154,10 +154,10 @@ namespace Terminal.Gui { } } - Rune _leftBracket = new Rune (Driver != null ? Glyphs.LeftBracket : '['); - Rune _rightBracket = new Rune (Driver != null ? Glyphs.RightBracket : ']'); - Rune _leftDefault = new Rune (Driver != null ? Glyphs.LeftDefaultIndicator : '<'); - Rune _rightDefault = new Rune (Driver != null ? Glyphs.RightDefaultIndicator : '>'); + Rune _leftBracket = new Rune (Driver != null ? Driver.LeftBracket : '['); + Rune _rightBracket = new Rune (Driver != null ? Driver.RightBracket : ']'); + Rune _leftDefault = new Rune (Driver != null ? Driver.LeftDefaultIndicator : '<'); + Rune _rightDefault = new Rune (Driver != null ? Driver.RightDefaultIndicator : '>'); internal void Update () { diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 23975771d..b0da9070c 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -320,32 +320,32 @@ namespace Terminal.Gui { Driver.SetAttribute (item == null ? ColorScheme.Normal : i == current ? ColorScheme.Focus : ColorScheme.Normal); if (item == null) { Move (0, i + 1); - Driver.AddRune (Glyphs.LeftTee); + Driver.AddRune (Driver.LeftTee); } else Move (1, i + 1); Driver.SetAttribute (DetermineColorSchemeFor (item, i)); for (int p = 0; p < Frame.Width - 2; p++) if (item == null) - Driver.AddRune (Glyphs.HLine); + Driver.AddRune (Driver.HLine); else if (p == Frame.Width - 3 && barItems.Children [i].SubMenu != null) - Driver.AddRune (Glyphs.RightArrow); + Driver.AddRune (Driver.RightArrow); else Driver.AddRune (' '); if (item == null) { Move (Frame.Right - 1, i + 1); - Driver.AddRune (Glyphs.RightTee); + Driver.AddRune (Driver.RightTee); continue; } ustring textToDraw; - var checkChar = Glyphs.Selected; - var uncheckedChar = Glyphs.UnSelected; + var checkChar = Driver.Selected; + var uncheckedChar = Driver.UnSelected; if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked)) { - checkChar = Glyphs.Checked; - uncheckedChar = Glyphs.UnChecked; + checkChar = Driver.Checked; + uncheckedChar = Driver.UnChecked; } // Support Checked even though CHeckType wasn't set diff --git a/Terminal.Gui/Views/ProgressBar.cs b/Terminal.Gui/Views/ProgressBar.cs index 0fad6daea..18a04c5dd 100644 --- a/Terminal.Gui/Views/ProgressBar.cs +++ b/Terminal.Gui/Views/ProgressBar.cs @@ -89,7 +89,7 @@ namespace Terminal.Gui { Move (0, 0); for (int i = 0; i < top; i++) if (i == activityPos) - Driver.AddRune (Glyphs.Stipple); + Driver.AddRune (Driver.Stipple); else Driver.AddRune (' '); } else { @@ -97,7 +97,7 @@ namespace Terminal.Gui { int mid = (int)(fraction * top); int i; for (i = 0; i < mid; i++) - Driver.AddRune (Glyphs.Stipple); + Driver.AddRune (Driver.Stipple); for (; i < top; i++) Driver.AddRune (' '); } diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index 4edf3fa2f..7bcd7aaee 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -141,7 +141,7 @@ namespace Terminal.Gui { for (int i = 0; i < radioLabels.Count; i++) { Move (0, i); Driver.SetAttribute (ColorScheme.Normal); - Driver.AddStr (ustring.Make(new Rune[] { (i == selected ? Glyphs.Selected : Glyphs.UnSelected), ' '})); + Driver.AddStr (ustring.Make(new Rune[] { (i == selected ? Driver.Selected : Driver.UnSelected), ' '})); DrawHotString (radioLabels [i], HasFocus && i == cursor, ColorScheme); } base.Redraw (bounds); diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index e1d029238..ad4ccb63c 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -148,18 +148,18 @@ namespace Terminal.Gui { var by2 = (position + bh) * bh / Size; Move (col, 0); - Driver.AddRune (Glyphs.UpArrow); + Driver.AddRune (Driver.UpArrow); Move (col, Bounds.Height - 1); - Driver.AddRune (Glyphs.DownArrow); + Driver.AddRune (Driver.DownArrow); } else { bh -= 2; var by1 = position * bh / Size; var by2 = (position + bh) * bh / Size; Move (col, 0); - Driver.AddRune (Glyphs.UpArrow); + Driver.AddRune (Driver.UpArrow); Move (col, Bounds.Height - 1); - Driver.AddRune (Glyphs.DownArrow); + Driver.AddRune (Driver.DownArrow); bool hasTopTee = false; bool hasDiamond = false; @@ -167,22 +167,22 @@ namespace Terminal.Gui { for (int y = 0; y < bh; y++) { Move (col, y + 1); if ((y < by1 || y > by2) && ((position > 0 && !hasTopTee) || (hasTopTee && hasBottomTee))) { - special = Glyphs.Stipple; + special = Driver.Stipple; } else { if (y != by2 && y > 1 && by2 - by1 == 0 && by1 < bh - 1 && hasTopTee && !hasDiamond) { hasDiamond = true; - special = Glyphs.Diamond; + special = Driver.Diamond; } else { if (y == by1 && !hasTopTee) { hasTopTee = true; posTopTee = y; - special = Glyphs.TopTee; + special = Driver.TopTee; } else if ((y >= by2 || by2 == 0) && !hasBottomTee) { hasBottomTee = true; posBottomTee = y; - special = Glyphs.BottomTee; + special = Driver.BottomTee; } else { - special = Glyphs.VLine; + special = Driver.VLine; } } } @@ -190,7 +190,7 @@ namespace Terminal.Gui { } if (!hasTopTee) { Move (col, Bounds.Height - 2); - Driver.AddRune (Glyphs.TopTee); + Driver.AddRune (Driver.TopTee); } } } else { @@ -206,37 +206,37 @@ namespace Terminal.Gui { var bx2 = (position + bw) * bw / Size; Move (0, row); - Driver.AddRune (Glyphs.LeftArrow); - Driver.AddRune (Glyphs.RightArrow); + Driver.AddRune (Driver.LeftArrow); + Driver.AddRune (Driver.RightArrow); } else { bw -= 2; var bx1 = position * bw / Size; var bx2 = (position + bw) * bw / Size; Move (0, row); - Driver.AddRune (Glyphs.LeftArrow); + Driver.AddRune (Driver.LeftArrow); bool hasLeftTee = false; bool hasDiamond = false; bool hasRightTee = false; for (int x = 0; x < bw; x++) { if ((x < bx1 || x >= bx2 + 1) && ((position > 0 && !hasLeftTee) || (hasLeftTee && hasRightTee))) { - special = Glyphs.Stipple; + special = Driver.Stipple; } else { if (x != bx2 && x > 1 && bx2 - bx1 == 0 && bx1 < bw - 1 && hasLeftTee && !hasDiamond) { hasDiamond = true; - special = Glyphs.Diamond; + special = Driver.Diamond; } else { if (x == bx1 && !hasLeftTee) { hasLeftTee = true; posLeftTee = x; - special = Glyphs.LeftTee; + special = Driver.LeftTee; } else if ((x >= bx2 || bx2 == 0) && !hasRightTee) { hasRightTee = true; posRightTee = x; - special = Glyphs.RightTee; + special = Driver.RightTee; } else { - special = Glyphs.HLine; + special = Driver.HLine; } } } @@ -244,10 +244,10 @@ namespace Terminal.Gui { } if (!hasLeftTee) { Move (Bounds.Width -2, row); - Driver.AddRune (Glyphs.LeftTee); + Driver.AddRune (Driver.LeftTee); } - Driver.AddRune (Glyphs.RightArrow); + Driver.AddRune (Driver.RightArrow); } } } diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs index 6ef0227fd..214e42ed2 100644 --- a/Terminal.Gui/Views/StatusBar.cs +++ b/Terminal.Gui/Views/StatusBar.cs @@ -136,7 +136,7 @@ namespace Terminal.Gui { } if (i + 1 < Items.Length) { Driver.AddRune (' '); - Driver.AddRune (Glyphs.VLine); + Driver.AddRune (Driver.VLine); Driver.AddRune (' '); } } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index e8b241981..bdfa43b9f 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -266,11 +266,6 @@ namespace UICatalog { _numlock = new StatusItem (Key.CharMask, "Num", null); _scrolllock = new StatusItem (Key.CharMask, "Scroll", null); - var consoleFont = Application.Driver.GetFont (); - StatusItem font = new StatusItem (Key.Unknown, $"Console driver does not support querying font.", null); ; - if (consoleFont != null) { - font = new StatusItem (Key.Unknown, $"Console Font: {consoleFont.FaceName}, {consoleFont.Weight}, {consoleFont.Size.Width}x{consoleFont.Size.Height}", null); - } _statusBar = new StatusBar (new StatusItem [] { _capslock, _numlock, From 7ab256bc32caa51ff0a9ff9f43d770b9b1f8b111 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 15 Jun 2020 12:57:05 -0700 Subject: [PATCH 5/5] strip crlf chars from label --- Terminal.Gui/Views/Label.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index 96e7a66af..1bfa7a379 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -123,8 +123,6 @@ namespace Terminal.Gui { static ustring ClipAndJustify (ustring str, int width, TextAlignment talign) { - // Get rid of any '\r' added by Windows - str = str.Replace ("\r", ustring.Empty); int slen = str.RuneCount; if (slen > width) { var uints = str.ToRunes (width); @@ -166,12 +164,22 @@ namespace Terminal.Gui { Recalc (text, lines, Frame.Width, textAlignment, Bounds.Height > 1); } - static ustring ReplaceNonPrintables (ustring str) + static ustring StripCRLF (ustring str) { var runes = new List (); foreach (var r in str.ToRunes ()) { - if (r < 0x20) { - runes.Add (new Rune (r + 0x2400)); // U+25A1 □ WHITE SQUARE + if (r != '\r' && r != '\n') { + runes.Add (r); + } + } + return ustring.Make (runes); ; + } + static ustring ReplaceCRLFWithSpace (ustring str) + { + var runes = new List (); + foreach (var r in str.ToRunes ()) { + if (r == '\r' || r == '\n') { + runes.Add (new Rune (' ')); // r + 0x2400)); // U+25A1 □ WHITE SQUARE } else { runes.Add (r); } @@ -184,7 +192,7 @@ namespace Terminal.Gui { int start = 0, end; var lines = new List (); - text = ReplaceNonPrintables (text); + text = StripCRLF (text); while ((end = start + margin) < text.Length) { while (text [end] != ' ' && end > start) @@ -208,7 +216,7 @@ namespace Terminal.Gui { lineResult.Clear (); if (wordWrap == false) { - textStr = ReplaceNonPrintables (textStr); + textStr = ReplaceCRLFWithSpace (textStr); lineResult.Add (ClipAndJustify (textStr, width, talign)); return; }