From 02cb6448128b15a903d79e82ae7fe9111f66cdb5 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 28 Sep 2020 17:15:33 -0700 Subject: [PATCH 1/7] Use glyphs for checkmarks & selection --- .../CursesDriver/CursesDriver.cs | 10 -- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 27 --- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 27 --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 27 --- Terminal.Gui/Views/Checkbox.cs | 9 +- Terminal.Gui/Views/ListView.cs | 24 ++- Terminal.Gui/Views/Menu.cs | 5 +- UICatalog/Scenarios/ListViewWithSelection.cs | 155 ++++++++++++++++++ 8 files changed, 181 insertions(+), 103 deletions(-) create mode 100644 UICatalog/Scenarios/ListViewWithSelection.cs diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 4ba273444..828dca838 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -531,20 +531,10 @@ namespace Terminal.Gui { 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 (); diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 11cd1c912..13e670c4f 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -182,33 +182,6 @@ namespace Terminal.Gui { 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 (); } diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index 1fe8f01c7..cf2f9e31d 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -152,33 +152,6 @@ namespace Terminal.Gui { 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) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index aaf324449..ab2e083b9 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -563,33 +563,6 @@ namespace Terminal.Gui { 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)] diff --git a/Terminal.Gui/Views/Checkbox.cs b/Terminal.Gui/Views/Checkbox.cs index 898c4658f..8d6b8a9a0 100644 --- a/Terminal.Gui/Views/Checkbox.cs +++ b/Terminal.Gui/Views/Checkbox.cs @@ -115,11 +115,12 @@ namespace Terminal.Gui { { Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal); Move (0, 0); - Driver.AddStr (Checked ? "[x] " : "[ ] "); - Move (4, 0); + Driver.AddRune (Checked ? Driver.Checked : Driver.UnChecked); + Driver.AddRune (' '); + Move (2, 0); Driver.AddStr (Text); if (hot_pos != -1) { - Move (4 + hot_pos, 0); + Move (2 + hot_pos, 0); Driver.SetAttribute (HasFocus ? ColorScheme.HotFocus : ColorScheme.HotNormal); Driver.AddRune (hot_key); } @@ -128,7 +129,7 @@ namespace Terminal.Gui { /// public override void PositionCursor () { - Move (1, 0); + Move (0, 0); } /// diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index b4bfe8ba7..c956717a3 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -180,7 +180,19 @@ namespace Terminal.Gui { /// /// If set to true allows more than one item to be selected. If false only allow one item selected. /// - public bool AllowsMultipleSelection { get; set; } = true; + public bool AllowsMultipleSelection { get => allowsMultipleSelection; + set { + allowsMultipleSelection = value; + if (Source != null && !allowsMultipleSelection) { + // Clear all selections except selected + for (int i = 0; i < Source.Count; i++) { + if (Source.IsMarked (i) && i != selected) { + Source.SetMark (i, false); + } + } + } + } + } /// /// Gets or sets the item that is displayed at the top of the . @@ -291,7 +303,7 @@ namespace Terminal.Gui { } var item = top; bool focused = HasFocus; - int col = allowsMarking ? 4 : 0; + int col = allowsMarking ? 2 : 0; for (int row = 0; row < f.Height; row++, item++) { bool isSelected = item == selected; @@ -308,7 +320,8 @@ namespace Terminal.Gui { Driver.AddRune (' '); } else { if (allowsMarking) { - Driver.AddStr (source.IsMarked (item) ? (AllowsMultipleSelection ? "[x] " : "(o)") : (AllowsMultipleSelection ? "[ ] " : "( )")); + Driver.AddRune (source.IsMarked (item) ? (AllowsMultipleSelection ? Driver.Selected : Driver.Checked) : (AllowsMultipleSelection ? Driver.UnSelected : Driver.UnChecked)); + Driver.AddRune (' '); } Source.Render (this, Driver, isSelected, item, col, row, f.Width - col); } @@ -537,6 +550,7 @@ namespace Terminal.Gui { } int lastSelectedItem = -1; + private bool allowsMultipleSelection = true; /// /// Invokes the SelectedChanged event if it is defined. @@ -593,9 +607,9 @@ namespace Terminal.Gui { public override void PositionCursor () { if (allowsMarking) - Move (1, selected - top); - else Move (0, selected - top); + else + Move (Bounds.Width - 1, selected - top); } /// diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index fb6c31ab9..67d27a85f 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -398,11 +398,10 @@ namespace Terminal.Gui { uncheckedChar = Driver.UnChecked; } - // Support Checked even though CHeckType wasn't set + // Support Checked even though CheckType wasn't set if (item.Checked) { textToDraw = ustring.Make (new Rune [] { checkChar, ' ' }) + item.Title; - } else if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked) || - item.CheckType.HasFlag (MenuItemCheckStyle.Radio)) { + } else if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked) || item.CheckType.HasFlag (MenuItemCheckStyle.Radio)) { textToDraw = ustring.Make (new Rune [] { uncheckedChar, ' ' }) + item.Title; } else { textToDraw = item.Title; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs new file mode 100644 index 000000000..5a0e03daa --- /dev/null +++ b/UICatalog/Scenarios/ListViewWithSelection.cs @@ -0,0 +1,155 @@ +using NStack; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Terminal.Gui; + +namespace UICatalog { + [ScenarioMetadata (Name: "List View With Selection", Description: "ListView with colunns and selection")] + [ScenarioCategory ("Controls")] + class ListViewWithSelection : Scenario { + + public CheckBox _customRenderCB; + public CheckBox _allowMarkingCB; + public CheckBox _allowMultipleCB; + public ListView _listView; + + public List _scenarios = Scenario.GetDerivedClasses().OrderBy (t => Scenario.ScenarioMetadata.GetName (t)).ToList (); + + public override void Setup () + { + _customRenderCB = new CheckBox ("Render with columns") { + X = 0, + Y = 0, + Height = 1, + }; + Win.Add (_customRenderCB); + _customRenderCB.Toggled += _customRenderCB_Toggled; ; + + _allowMarkingCB = new CheckBox ("Allow Marking") { + X = Pos.Right (_customRenderCB) + 1, + Y = 0, + Height = 1, + }; + Win.Add (_allowMarkingCB); + _allowMarkingCB.Toggled += AllowMarkingCB_Toggled; + + _allowMultipleCB = new CheckBox ("Allow Multi-Select") { + X = Pos.Right (_allowMarkingCB) + 1, + Y = 0, + Height = 1, + Visible = _allowMarkingCB.Checked + }; + Win.Add (_allowMultipleCB); + _allowMultipleCB.Toggled += AllowMultipleCB_Toggled; + + _listView = new ListView () { + X = 1, + Y = 2, + Height = Dim.Fill (), + Width = Dim.Fill (1), + //ColorScheme = Colors.TopLevel, + AllowsMarking = false, + AllowsMultipleSelection = false + }; + Win.Add (_listView); + + + _listView.SetSource (_scenarios); + + } + + private void _customRenderCB_Toggled (bool prev) + { + if (prev) { + _listView.SetSource (_scenarios); + } else { + _listView.Source = new ScenarioListDataSource (_scenarios); + } + + Win.SetNeedsDisplay (); + } + + private void AllowMarkingCB_Toggled (bool prev) + { + _listView.AllowsMarking = !prev; + _allowMultipleCB.Visible = _listView.AllowsMarking; + Win.SetNeedsDisplay (); + } + + private void AllowMultipleCB_Toggled (bool prev) + { + _listView.AllowsMultipleSelection = !prev; + Win.SetNeedsDisplay (); + } + + // This is basicaly the same implementation used by the UICatalog main window + internal class ScenarioListDataSource : IListDataSource { + int _nameColumnWidth = 30; + private List scenarios; + BitArray marks; + int count; + + public List Scenarios { + get => scenarios; + set { + if (value != null) { + count = value.Count; + marks = new BitArray (count); + scenarios = value; + } + } + } + public bool IsMarked (int item) + { + if (item >= 0 && item < count) + return marks [item]; + return false; + } + + public int Count => Scenarios != null ? Scenarios.Count : 0; + + public ScenarioListDataSource (List itemList) => Scenarios = itemList; + + public void Render (ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width) + { + container.Move (col, line); + // Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible + var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [item])); + RenderUstr (driver, $"{s} {Scenario.ScenarioMetadata.GetDescription (Scenarios [item])}", col, line, width); + } + + public void SetMark (int item, bool value) + { + if (item >= 0 && item < count) + marks [item] = value; + } + + // A slightly adapted method from: https://github.com/migueldeicaza/gui.cs/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461 + private void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width) + { + int used = 0; + int index = 0; + while (index < ustr.Length) { + (var rune, var size) = Utf8.DecodeRune (ustr, index, index - ustr.Length); + var count = Rune.ColumnWidth (rune); + if (used + count >= width) break; + driver.AddRune (rune); + used += count; + index += size; + } + + while (used < width) { + driver.AddRune (' '); + used++; + } + } + + public IList ToList () + { + return Scenarios; + } + } + } +} \ No newline at end of file From c3524e6b194c5fee19cfc4f55b3c8549764ed1fe Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 28 Sep 2020 17:29:36 -0700 Subject: [PATCH 2/7] fixed glyph that wasn't working with Cascadia --- Terminal.Gui/Core/ConsoleDriver.cs | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index 612c22c60..2ad8e9954 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -913,132 +913,132 @@ namespace Terminal.Gui { /// /// Horizontal line character. /// - public Rune HLine; + public Rune HLine = '\u2500'; /// /// Vertical line character. /// - public Rune VLine; + public Rune VLine = '\u2502'; /// /// Stipple pattern /// - public Rune Stipple; + public Rune Stipple = '\u2591'; /// /// Diamond character /// - public Rune Diamond; + public Rune Diamond = '\u25ca'; /// /// Upper left corner /// - public Rune ULCorner; + public Rune ULCorner = '\u250C'; /// /// Lower left corner /// - public Rune LLCorner; + public Rune LLCorner = '\u2514'; /// /// Upper right corner /// - public Rune URCorner; + public Rune URCorner = '\u2510'; /// /// Lower right corner /// - public Rune LRCorner; + public Rune LRCorner = '\u2518'; /// /// Left tee /// - public Rune LeftTee; + public Rune LeftTee = '\u251c'; /// /// Right tee /// - public Rune RightTee; + public Rune RightTee = '\u2524'; /// /// Top tee /// - public Rune TopTee; + public Rune TopTee = '\u252c'; /// /// The bottom tee. /// - public Rune BottomTee; + public Rune BottomTee = '\u2534'; /// /// Checkmark. /// - public Rune Checked; + public Rune Checked = '\u221a'; /// /// Un-checked checkmark. /// - public Rune UnChecked; + public Rune UnChecked = '\u2574'; /// /// Selected mark. /// - public Rune Selected; + public Rune Selected = '\u25cf'; /// /// Un-selected selected mark. /// - public Rune UnSelected; + public Rune UnSelected = '\u25cc'; /// /// Right Arrow. /// - public Rune RightArrow; + public Rune RightArrow = '\u25ba'; /// /// Left Arrow. /// - public Rune LeftArrow; + public Rune LeftArrow = '\u25c4'; /// /// Down Arrow. /// - public Rune DownArrow; + public Rune DownArrow = '\u25bc'; /// /// Up Arrow. /// - public Rune UpArrow; + public Rune UpArrow = '\u25b2'; /// /// Left indicator for default action (e.g. for ). /// - public Rune LeftDefaultIndicator; + public Rune LeftDefaultIndicator = '\u25e6'; /// /// Right indicator for default action (e.g. for ). /// - public Rune RightDefaultIndicator; + public Rune RightDefaultIndicator = '\u25e6'; /// /// Left frame/bracket (e.g. '[' for ). /// - public Rune LeftBracket; + public Rune LeftBracket = '['; /// /// Right frame/bracket (e.g. ']' for ). /// - public Rune RightBracket; + public Rune RightBracket = ']'; /// /// On Segment indicator for meter views (e.g. . /// - public Rune OnMeterSegment; + public Rune OnMeterSegment = '\u258c'; /// /// Off Segment indicator for meter views (e.g. . /// - public Rune OffMeterSegement; + public Rune OffMeterSegement = ' '; /// /// Make the attribute for the foreground and background colors. From 36db9ffb6475c80aad8a3e1510d1d0663f663d72 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 29 Sep 2020 07:26:48 -0700 Subject: [PATCH 3/7] bumped version to 1.00.00-pre as a test of nuget --- Terminal.Gui/Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Directory.Build.props b/Terminal.Gui/Directory.Build.props index b5334f688..2db58eb0f 100644 --- a/Terminal.Gui/Directory.Build.props +++ b/Terminal.Gui/Directory.Build.props @@ -1,9 +1,9 @@ - 0.90.2 - 0.90.2 - 0.90.2 + 1.00.0-pre + 1.00.0-pre + 1.00.0-pre Miguel de Icaza, Charlie Kindel (@tig), @BDisp From 1c4c0264a7327aa9235fa9c6399d9c152d01371b Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 29 Sep 2020 08:25:15 -0700 Subject: [PATCH 4/7] trying new format --- Terminal.Gui/Directory.Build.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Terminal.Gui/Directory.Build.props b/Terminal.Gui/Directory.Build.props index 2db58eb0f..7cf3dcffb 100644 --- a/Terminal.Gui/Directory.Build.props +++ b/Terminal.Gui/Directory.Build.props @@ -1,9 +1,9 @@ - 1.00.0-pre - 1.00.0-pre - 1.00.0-pre + 1.00-pre.99.1 + 0.99.1 + 0.99.1 Miguel de Icaza, Charlie Kindel (@tig), @BDisp From f77fa585b6484b25a92fe69d3d05f9c5345692a0 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 29 Sep 2020 08:44:03 -0700 Subject: [PATCH 5/7] realized I had two directory.build.props --- .github/workflows/publish.yml | 2 +- Directory.Build.props | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 Directory.Build.props diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 54c2d6aab..3c3a7c3a1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,7 +27,7 @@ jobs: PACKAGE_NAME: Terminal.Gui # Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH - VERSION_FILE_PATH: Directory.Build.props + VERSION_FILE_PATH: Terminal.Gui/Directory.Build.props # Regex pattern to extract version info in a capturing group VERSION_REGEX: ^\s*(.*)<\/Version>\s*$ diff --git a/Directory.Build.props b/Directory.Build.props deleted file mode 100644 index 53f7dce48..000000000 --- a/Directory.Build.props +++ /dev/null @@ -1,10 +0,0 @@ - - - - 0.90.0 - 0.90.0 - 0.90.0 - Miguel de Icaza, Charlie Kindel (@tig), @BDisp - - - \ No newline at end of file From 04f2c64b8f77ed7b9d6ce0b772236ffd7727464b Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 29 Sep 2020 10:50:30 -0700 Subject: [PATCH 6/7] Revert "Use glyphs for checkmarks & selection" --- .../CursesDriver/CursesDriver.cs | 10 ++ .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 27 +++ Terminal.Gui/ConsoleDrivers/NetDriver.cs | 27 +++ Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 27 +++ Terminal.Gui/Core/ConsoleDriver.cs | 52 +++--- Terminal.Gui/Views/Checkbox.cs | 9 +- Terminal.Gui/Views/ListView.cs | 24 +-- Terminal.Gui/Views/Menu.cs | 5 +- UICatalog/Scenarios/ListViewWithSelection.cs | 155 ------------------ 9 files changed, 129 insertions(+), 207 deletions(-) delete mode 100644 UICatalog/Scenarios/ListViewWithSelection.cs diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 828dca838..4ba273444 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -531,10 +531,20 @@ namespace Terminal.Gui { 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 (); diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 13e670c4f..11cd1c912 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -182,6 +182,33 @@ namespace Terminal.Gui { 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 (); } diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index cf2f9e31d..1fe8f01c7 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -152,6 +152,33 @@ namespace Terminal.Gui { 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) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index ab2e083b9..aaf324449 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -563,6 +563,33 @@ namespace Terminal.Gui { 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)] diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs index 2ad8e9954..612c22c60 100644 --- a/Terminal.Gui/Core/ConsoleDriver.cs +++ b/Terminal.Gui/Core/ConsoleDriver.cs @@ -913,132 +913,132 @@ namespace Terminal.Gui { /// /// Horizontal line character. /// - public Rune HLine = '\u2500'; + public Rune HLine; /// /// Vertical line character. /// - public Rune VLine = '\u2502'; + public Rune VLine; /// /// Stipple pattern /// - public Rune Stipple = '\u2591'; + public Rune Stipple; /// /// Diamond character /// - public Rune Diamond = '\u25ca'; + public Rune Diamond; /// /// Upper left corner /// - public Rune ULCorner = '\u250C'; + public Rune ULCorner; /// /// Lower left corner /// - public Rune LLCorner = '\u2514'; + public Rune LLCorner; /// /// Upper right corner /// - public Rune URCorner = '\u2510'; + public Rune URCorner; /// /// Lower right corner /// - public Rune LRCorner = '\u2518'; + public Rune LRCorner; /// /// Left tee /// - public Rune LeftTee = '\u251c'; + public Rune LeftTee; /// /// Right tee /// - public Rune RightTee = '\u2524'; + public Rune RightTee; /// /// Top tee /// - public Rune TopTee = '\u252c'; + public Rune TopTee; /// /// The bottom tee. /// - public Rune BottomTee = '\u2534'; + public Rune BottomTee; /// /// Checkmark. /// - public Rune Checked = '\u221a'; + public Rune Checked; /// /// Un-checked checkmark. /// - public Rune UnChecked = '\u2574'; + public Rune UnChecked; /// /// Selected mark. /// - public Rune Selected = '\u25cf'; + public Rune Selected; /// /// Un-selected selected mark. /// - public Rune UnSelected = '\u25cc'; + public Rune UnSelected; /// /// Right Arrow. /// - public Rune RightArrow = '\u25ba'; + public Rune RightArrow; /// /// Left Arrow. /// - public Rune LeftArrow = '\u25c4'; + public Rune LeftArrow; /// /// Down Arrow. /// - public Rune DownArrow = '\u25bc'; + public Rune DownArrow; /// /// Up Arrow. /// - public Rune UpArrow = '\u25b2'; + public Rune UpArrow; /// /// Left indicator for default action (e.g. for ). /// - public Rune LeftDefaultIndicator = '\u25e6'; + public Rune LeftDefaultIndicator; /// /// Right indicator for default action (e.g. for ). /// - public Rune RightDefaultIndicator = '\u25e6'; + public Rune RightDefaultIndicator; /// /// Left frame/bracket (e.g. '[' for ). /// - public Rune LeftBracket = '['; + public Rune LeftBracket; /// /// Right frame/bracket (e.g. ']' for ). /// - public Rune RightBracket = ']'; + public Rune RightBracket; /// /// On Segment indicator for meter views (e.g. . /// - public Rune OnMeterSegment = '\u258c'; + public Rune OnMeterSegment; /// /// Off Segment indicator for meter views (e.g. . /// - public Rune OffMeterSegement = ' '; + public Rune OffMeterSegement; /// /// Make the attribute for the foreground and background colors. diff --git a/Terminal.Gui/Views/Checkbox.cs b/Terminal.Gui/Views/Checkbox.cs index 8d6b8a9a0..898c4658f 100644 --- a/Terminal.Gui/Views/Checkbox.cs +++ b/Terminal.Gui/Views/Checkbox.cs @@ -115,12 +115,11 @@ namespace Terminal.Gui { { Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal); Move (0, 0); - Driver.AddRune (Checked ? Driver.Checked : Driver.UnChecked); - Driver.AddRune (' '); - Move (2, 0); + Driver.AddStr (Checked ? "[x] " : "[ ] "); + Move (4, 0); Driver.AddStr (Text); if (hot_pos != -1) { - Move (2 + hot_pos, 0); + Move (4 + hot_pos, 0); Driver.SetAttribute (HasFocus ? ColorScheme.HotFocus : ColorScheme.HotNormal); Driver.AddRune (hot_key); } @@ -129,7 +128,7 @@ namespace Terminal.Gui { /// public override void PositionCursor () { - Move (0, 0); + Move (1, 0); } /// diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index c956717a3..b4bfe8ba7 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -180,19 +180,7 @@ namespace Terminal.Gui { /// /// If set to true allows more than one item to be selected. If false only allow one item selected. /// - public bool AllowsMultipleSelection { get => allowsMultipleSelection; - set { - allowsMultipleSelection = value; - if (Source != null && !allowsMultipleSelection) { - // Clear all selections except selected - for (int i = 0; i < Source.Count; i++) { - if (Source.IsMarked (i) && i != selected) { - Source.SetMark (i, false); - } - } - } - } - } + public bool AllowsMultipleSelection { get; set; } = true; /// /// Gets or sets the item that is displayed at the top of the . @@ -303,7 +291,7 @@ namespace Terminal.Gui { } var item = top; bool focused = HasFocus; - int col = allowsMarking ? 2 : 0; + int col = allowsMarking ? 4 : 0; for (int row = 0; row < f.Height; row++, item++) { bool isSelected = item == selected; @@ -320,8 +308,7 @@ namespace Terminal.Gui { Driver.AddRune (' '); } else { if (allowsMarking) { - Driver.AddRune (source.IsMarked (item) ? (AllowsMultipleSelection ? Driver.Selected : Driver.Checked) : (AllowsMultipleSelection ? Driver.UnSelected : Driver.UnChecked)); - Driver.AddRune (' '); + Driver.AddStr (source.IsMarked (item) ? (AllowsMultipleSelection ? "[x] " : "(o)") : (AllowsMultipleSelection ? "[ ] " : "( )")); } Source.Render (this, Driver, isSelected, item, col, row, f.Width - col); } @@ -550,7 +537,6 @@ namespace Terminal.Gui { } int lastSelectedItem = -1; - private bool allowsMultipleSelection = true; /// /// Invokes the SelectedChanged event if it is defined. @@ -607,9 +593,9 @@ namespace Terminal.Gui { public override void PositionCursor () { if (allowsMarking) - Move (0, selected - top); + Move (1, selected - top); else - Move (Bounds.Width - 1, selected - top); + Move (0, selected - top); } /// diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs index 67d27a85f..fb6c31ab9 100644 --- a/Terminal.Gui/Views/Menu.cs +++ b/Terminal.Gui/Views/Menu.cs @@ -398,10 +398,11 @@ namespace Terminal.Gui { uncheckedChar = Driver.UnChecked; } - // Support Checked even though CheckType wasn't set + // Support Checked even though CHeckType wasn't set if (item.Checked) { textToDraw = ustring.Make (new Rune [] { checkChar, ' ' }) + item.Title; - } else if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked) || item.CheckType.HasFlag (MenuItemCheckStyle.Radio)) { + } else if (item.CheckType.HasFlag (MenuItemCheckStyle.Checked) || + item.CheckType.HasFlag (MenuItemCheckStyle.Radio)) { textToDraw = ustring.Make (new Rune [] { uncheckedChar, ' ' }) + item.Title; } else { textToDraw = item.Title; diff --git a/UICatalog/Scenarios/ListViewWithSelection.cs b/UICatalog/Scenarios/ListViewWithSelection.cs deleted file mode 100644 index 5a0e03daa..000000000 --- a/UICatalog/Scenarios/ListViewWithSelection.cs +++ /dev/null @@ -1,155 +0,0 @@ -using NStack; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Terminal.Gui; - -namespace UICatalog { - [ScenarioMetadata (Name: "List View With Selection", Description: "ListView with colunns and selection")] - [ScenarioCategory ("Controls")] - class ListViewWithSelection : Scenario { - - public CheckBox _customRenderCB; - public CheckBox _allowMarkingCB; - public CheckBox _allowMultipleCB; - public ListView _listView; - - public List _scenarios = Scenario.GetDerivedClasses().OrderBy (t => Scenario.ScenarioMetadata.GetName (t)).ToList (); - - public override void Setup () - { - _customRenderCB = new CheckBox ("Render with columns") { - X = 0, - Y = 0, - Height = 1, - }; - Win.Add (_customRenderCB); - _customRenderCB.Toggled += _customRenderCB_Toggled; ; - - _allowMarkingCB = new CheckBox ("Allow Marking") { - X = Pos.Right (_customRenderCB) + 1, - Y = 0, - Height = 1, - }; - Win.Add (_allowMarkingCB); - _allowMarkingCB.Toggled += AllowMarkingCB_Toggled; - - _allowMultipleCB = new CheckBox ("Allow Multi-Select") { - X = Pos.Right (_allowMarkingCB) + 1, - Y = 0, - Height = 1, - Visible = _allowMarkingCB.Checked - }; - Win.Add (_allowMultipleCB); - _allowMultipleCB.Toggled += AllowMultipleCB_Toggled; - - _listView = new ListView () { - X = 1, - Y = 2, - Height = Dim.Fill (), - Width = Dim.Fill (1), - //ColorScheme = Colors.TopLevel, - AllowsMarking = false, - AllowsMultipleSelection = false - }; - Win.Add (_listView); - - - _listView.SetSource (_scenarios); - - } - - private void _customRenderCB_Toggled (bool prev) - { - if (prev) { - _listView.SetSource (_scenarios); - } else { - _listView.Source = new ScenarioListDataSource (_scenarios); - } - - Win.SetNeedsDisplay (); - } - - private void AllowMarkingCB_Toggled (bool prev) - { - _listView.AllowsMarking = !prev; - _allowMultipleCB.Visible = _listView.AllowsMarking; - Win.SetNeedsDisplay (); - } - - private void AllowMultipleCB_Toggled (bool prev) - { - _listView.AllowsMultipleSelection = !prev; - Win.SetNeedsDisplay (); - } - - // This is basicaly the same implementation used by the UICatalog main window - internal class ScenarioListDataSource : IListDataSource { - int _nameColumnWidth = 30; - private List scenarios; - BitArray marks; - int count; - - public List Scenarios { - get => scenarios; - set { - if (value != null) { - count = value.Count; - marks = new BitArray (count); - scenarios = value; - } - } - } - public bool IsMarked (int item) - { - if (item >= 0 && item < count) - return marks [item]; - return false; - } - - public int Count => Scenarios != null ? Scenarios.Count : 0; - - public ScenarioListDataSource (List itemList) => Scenarios = itemList; - - public void Render (ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width) - { - container.Move (col, line); - // Equivalent to an interpolated string like $"{Scenarios[item].Name, -widtestname}"; if such a thing were possible - var s = String.Format (String.Format ("{{0,{0}}}", -_nameColumnWidth), Scenario.ScenarioMetadata.GetName (Scenarios [item])); - RenderUstr (driver, $"{s} {Scenario.ScenarioMetadata.GetDescription (Scenarios [item])}", col, line, width); - } - - public void SetMark (int item, bool value) - { - if (item >= 0 && item < count) - marks [item] = value; - } - - // A slightly adapted method from: https://github.com/migueldeicaza/gui.cs/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461 - private void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width) - { - int used = 0; - int index = 0; - while (index < ustr.Length) { - (var rune, var size) = Utf8.DecodeRune (ustr, index, index - ustr.Length); - var count = Rune.ColumnWidth (rune); - if (used + count >= width) break; - driver.AddRune (rune); - used += count; - index += size; - } - - while (used < width) { - driver.AddRune (' '); - used++; - } - } - - public IList ToList () - { - return Scenarios; - } - } - } -} \ No newline at end of file From 29f6f497a07fdb82cf06e9f2d80b733676073b3e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Tue, 29 Sep 2020 10:53:27 -0700 Subject: [PATCH 7/7] Revert "bumped version to 1.00-pre.99.1 as a test of nuget" --- .github/workflows/publish.yml | 2 +- Directory.Build.props | 10 ++++++++++ Terminal.Gui/Directory.Build.props | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 Directory.Build.props diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3c3a7c3a1..54c2d6aab 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,7 +27,7 @@ jobs: PACKAGE_NAME: Terminal.Gui # Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH - VERSION_FILE_PATH: Terminal.Gui/Directory.Build.props + VERSION_FILE_PATH: Directory.Build.props # Regex pattern to extract version info in a capturing group VERSION_REGEX: ^\s*(.*)<\/Version>\s*$ diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 000000000..53f7dce48 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,10 @@ + + + + 0.90.0 + 0.90.0 + 0.90.0 + Miguel de Icaza, Charlie Kindel (@tig), @BDisp + + + \ No newline at end of file diff --git a/Terminal.Gui/Directory.Build.props b/Terminal.Gui/Directory.Build.props index 7cf3dcffb..b5334f688 100644 --- a/Terminal.Gui/Directory.Build.props +++ b/Terminal.Gui/Directory.Build.props @@ -1,9 +1,9 @@ - 1.00-pre.99.1 - 0.99.1 - 0.99.1 + 0.90.2 + 0.90.2 + 0.90.2 Miguel de Icaza, Charlie Kindel (@tig), @BDisp