Removed Attribute.HasValidColors

This commit is contained in:
Tigger Kindel
2023-10-10 11:23:08 -06:00
committed by Tig
parent c2b58b285b
commit 3ff5453c56
4 changed files with 30 additions and 72 deletions

View File

@@ -390,7 +390,8 @@ public abstract class ConsoleDriver {
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;
}

View File

@@ -744,12 +744,13 @@ namespace Terminal.Gui {
[JsonIgnore]
public bool Initialized { get; internal set; }
/// <summary>
/// Returns <see langword="true"/> if the Attribute is valid (both foreground and background have valid color values).
/// </summary>
/// <returns></returns>
[JsonIgnore]
public bool HasValidColors => (int)Foreground.ColorName > -1 && (int)Background.ColorName > -1;
//// TODO: This no longer makes sense - remove it
///// <summary>
///// Returns <see langword="true"/> if the Attribute is valid (both foreground and background have valid color values).
///// </summary>
///// <returns></returns>
//[JsonIgnore]
//public bool HasValidColors => (int)Foreground.ColorName > -1 && (int)Background.ColorName > -1;
/// <inheritdoc />
public override string ToString ()
@@ -820,9 +821,9 @@ namespace Terminal.Gui {
public Attribute Normal {
get { return _normal; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_normal = value;
}
}
@@ -833,9 +834,9 @@ namespace Terminal.Gui {
public Attribute Focus {
get { return _focus; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_focus = value;
}
}
@@ -846,9 +847,9 @@ namespace Terminal.Gui {
public Attribute HotNormal {
get { return _hotNormal; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_hotNormal = value;
}
}
@@ -859,9 +860,9 @@ namespace Terminal.Gui {
public Attribute HotFocus {
get { return _hotFocus; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_hotFocus = value;
}
}
@@ -872,9 +873,9 @@ namespace Terminal.Gui {
public Attribute Disabled {
get { return _disabled; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_disabled = value;
}
}

View File

@@ -545,17 +545,7 @@ namespace Terminal.Gui {
}
}
private Attribute? GetAttributeForIntersects (IntersectionDefinition? [] intersects)
{
var set = new List<IntersectionDefinition?> (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)
{

View File

@@ -110,19 +110,19 @@ public class AttributeTests {
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 class AttributeTests {
Assert.Equal (bg, attr.Background);
}
[Fact]
public void Get_Asserts_NoDriver ()
{
Assert.Throws<InvalidOperationException> (() => 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 class AttributeTests {
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);