Skip to content

Commit

Permalink
Removed Attribute.HasValidColors
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Oct 10, 2023
1 parent e7dd0c1 commit d21f67e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 72 deletions.
3 changes: 2 additions & 1 deletion Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
43 changes: 22 additions & 21 deletions Terminal.Gui/Drawing/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,13 @@ public bool Equals (Attribute other)
[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 ()
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -833,9 +834,9 @@ public Attribute Normal {
public Attribute Focus {
get { return _focus; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_focus = value;
}
}
Expand All @@ -846,9 +847,9 @@ public Attribute Focus {
public Attribute HotNormal {
get { return _hotNormal; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_hotNormal = value;
}
}
Expand All @@ -859,9 +860,9 @@ public Attribute HotNormal {
public Attribute HotFocus {
get { return _hotFocus; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_hotFocus = value;
}
}
Expand All @@ -872,9 +873,9 @@ public Attribute HotFocus {
public Attribute Disabled {
get { return _disabled; }
set {
if (!value.HasValidColors) {
return;
}
//if (!value.HasValidColors) {
// return;
//}
_disabled = value;
}
}
Expand Down
12 changes: 1 addition & 11 deletions Terminal.Gui/Drawing/LineCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,7 @@ public override void SetGlyphs ()
}
}

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)
{
Expand Down
44 changes: 5 additions & 39 deletions UnitTests/Drawing/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -271,40 +271,6 @@ public void Make_Creates_NoDriver ()
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 ()
Expand All @@ -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);
Expand Down

0 comments on commit d21f67e

Please sign in to comment.