From d21f67e0c9b32ae4c0617e5cce5e3d00156e2af6 Mon Sep 17 00:00:00 2001 From: Tigger Kindel Date: Tue, 10 Oct 2023 11:23:08 -0600 Subject: [PATCH] Removed Attribute.HasValidColors --- Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs | 3 +- Terminal.Gui/Drawing/Color.cs | 43 +++++++++---------- Terminal.Gui/Drawing/LineCanvas.cs | 12 +----- UnitTests/Drawing/AttributeTests.cs | 44 +++----------------- 4 files changed, 30 insertions(+), 72 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index bea8cb0c71..b2a250fe26 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -390,7 +390,8 @@ public virtual bool Force16Colors { public Attribute CurrentAttribute { get => _currentAttribute; set { - if (value is { Initialized: false, HasValidColors: true } && Application.Driver != null) { + //if (value is { Initialized: false, HasValidColors: true } && Application.Driver != null) { + if (value is { Initialized: false } && Application.Driver != null) { _currentAttribute = new Attribute (value.Foreground, value.Background); return; } diff --git a/Terminal.Gui/Drawing/Color.cs b/Terminal.Gui/Drawing/Color.cs index a05d945ce3..8bdb46ae7b 100644 --- a/Terminal.Gui/Drawing/Color.cs +++ b/Terminal.Gui/Drawing/Color.cs @@ -744,12 +744,13 @@ public bool Equals (Attribute other) [JsonIgnore] public bool Initialized { get; internal set; } - /// - /// Returns if the Attribute is valid (both foreground and background have valid color values). - /// - /// - [JsonIgnore] - public bool HasValidColors => (int)Foreground.ColorName > -1 && (int)Background.ColorName > -1; + //// TODO: This no longer makes sense - remove it + ///// + ///// Returns if the Attribute is valid (both foreground and background have valid color values). + ///// + ///// + //[JsonIgnore] + //public bool HasValidColors => (int)Foreground.ColorName > -1 && (int)Background.ColorName > -1; /// public override string ToString () @@ -820,9 +821,9 @@ public ColorScheme (Attribute attribute) public Attribute Normal { get { return _normal; } set { - if (!value.HasValidColors) { - return; - } + //if (!value.HasValidColors) { + // return; + //} _normal = value; } } @@ -833,9 +834,9 @@ public Attribute Normal { public Attribute Focus { get { return _focus; } set { - if (!value.HasValidColors) { - return; - } + //if (!value.HasValidColors) { + // return; + //} _focus = value; } } @@ -846,9 +847,9 @@ public Attribute Focus { public Attribute HotNormal { get { return _hotNormal; } set { - if (!value.HasValidColors) { - return; - } + //if (!value.HasValidColors) { + // return; + //} _hotNormal = value; } } @@ -859,9 +860,9 @@ public Attribute HotNormal { public Attribute HotFocus { get { return _hotFocus; } set { - if (!value.HasValidColors) { - return; - } + //if (!value.HasValidColors) { + // return; + //} _hotFocus = value; } } @@ -872,9 +873,9 @@ public Attribute HotFocus { public Attribute Disabled { get { return _disabled; } set { - if (!value.HasValidColors) { - return; - } + //if (!value.HasValidColors) { + // return; + //} _disabled = value; } } diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas.cs index b3171f77f1..ca20b21eba 100644 --- a/Terminal.Gui/Drawing/LineCanvas.cs +++ b/Terminal.Gui/Drawing/LineCanvas.cs @@ -545,17 +545,7 @@ public override void SetGlyphs () } } - private Attribute? GetAttributeForIntersects (IntersectionDefinition? [] intersects) - { - var set = new List (intersects.Where (i => i!.Line.Attribute?.HasValidColors ?? false)); - - if (set.Count == 0) { - return null; - } - - return set [0]!.Line.Attribute; - - } + private Attribute? GetAttributeForIntersects (IntersectionDefinition? [] intersects) =>intersects [0]!.Line.Attribute; private Cell? GetCellForIntersects (ConsoleDriver driver, IntersectionDefinition? [] intersects) { diff --git a/UnitTests/Drawing/AttributeTests.cs b/UnitTests/Drawing/AttributeTests.cs index 51f46e150c..df547f97d0 100644 --- a/UnitTests/Drawing/AttributeTests.cs +++ b/UnitTests/Drawing/AttributeTests.cs @@ -110,19 +110,19 @@ public void Constuctors_Constuct () attr = new Attribute (fg, bg); Assert.True (attr.Initialized); - Assert.True (attr.HasValidColors); + //Assert.True (attr.HasValidColors); Assert.Equal (fg, attr.Foreground); Assert.Equal (bg, attr.Background); attr = new Attribute (fg); Assert.True (attr.Initialized); - Assert.True (attr.HasValidColors); + //Assert.True (attr.HasValidColors); Assert.Equal (fg, attr.Foreground); Assert.Equal (fg, attr.Background); attr = new Attribute (bg); Assert.True (attr.Initialized); - Assert.True (attr.HasValidColors); + //Assert.True (attr.HasValidColors); Assert.Equal (bg, attr.Foreground); Assert.Equal (bg, attr.Background); @@ -271,40 +271,6 @@ public void Make_Creates_NoDriver () Assert.Equal (bg, attr.Background); } - [Fact] - public void Get_Asserts_NoDriver () - { - Assert.Throws (() => Attribute.Get ()); - } - - [Fact] - public void Get_Gets () - { - var driver = new FakeDriver (); - Application.Init (driver); - driver.Init (() => { }); - - var value = 42; - var fg = new Color (); - fg = (Color)Color.Red; - - var bg = new Color (); - bg = (Color)Color.Blue; - - var attr = new Attribute (value, fg, bg); - - driver.SetAttribute (attr); - - var ret_attr = Attribute.Get (); - - Assert.Equal (value, ret_attr.Value); - Assert.Equal (fg, ret_attr.Foreground); - Assert.Equal (bg, ret_attr.Background); - - driver.End (); - Application.Shutdown (); - } - [Fact] [AutoInitShutdown] public void GetColors_Based_On_Value () @@ -321,10 +287,10 @@ public void GetColors_Based_On_Value () public void IsValid_Tests () { var attr = new Attribute (); - Assert.True (attr.HasValidColors); + //Assert.True (attr.HasValidColors); attr = new Attribute (Color.Red, Color.Green); - Assert.True (attr.HasValidColors); + //Assert.True (attr.HasValidColors); //attr = new Attribute (Color.Red, (Color)(-1)); //Assert.False (attr.HasValidColors);