Skip to content

Commit

Permalink
imp - Added ColorTools safety guards for tests on CI
Browse files Browse the repository at this point in the history
---

We've added exception handlers to the main config color tools.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Feb 23, 2024
1 parent 0bcbc84 commit e67fb89
Showing 1 changed file with 129 additions and 14 deletions.
143 changes: 129 additions & 14 deletions public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
using Nitrocid.Network;
using Terminaux.Inputs.Styles.Selection;
using Terminaux.Inputs.Interactive;
using Nitrocid.Kernel.Debugging;

namespace Nitrocid.Kernel.Configuration.Instances
{
Expand Down Expand Up @@ -143,24 +144,84 @@ public string CurrentLanguage
/// </summary>
public bool ColorBlind
{
get => ColorTools.GlobalSettings.EnableColorTransformation;
set => ColorTools.GlobalSettings.EnableColorTransformation = value;
get
{
try
{
return ColorTools.GlobalSettings.EnableColorTransformation;
}
catch
{
return false;
}
}
set
{
try
{
ColorTools.GlobalSettings.EnableColorTransformation = value;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.GlobalSettings.EnableColorTransformation)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
/// The type of color blindness, whether it's protan, deuter, or tritan.
/// </summary>
public int BlindnessTransformationFormula
{
get => (int)ColorTools.GlobalSettings.ColorTransformationFormula;
set => ColorTools.GlobalSettings.ColorTransformationFormula = (TransformationFormula)value;
get
{
try
{
return (int)ColorTools.GlobalSettings.ColorTransformationFormula;
}
catch
{
return (int)TransformationFormula.Deutan;
}
}
set
{
try
{
ColorTools.GlobalSettings.ColorTransformationFormula = (TransformationFormula)value;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.GlobalSettings.ColorTransformationFormula)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
/// How severe is the color blindness?
/// </summary>
public double BlindnessSeverity
{
get => ColorTools.GlobalSettings.ColorBlindnessSeverity;
set => ColorTools.GlobalSettings.ColorBlindnessSeverity = value;
get
{
try
{
return ColorTools.GlobalSettings.ColorBlindnessSeverity;
}
catch
{
return 0.6d;
}
}
set
{
try
{
ColorTools.GlobalSettings.ColorBlindnessSeverity = value;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.GlobalSettings.ColorBlindnessSeverity)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
/// Enables beeping upon shutting down the kernel.
Expand All @@ -175,8 +236,28 @@ public double BlindnessSeverity
/// </summary>
public bool ColorBlindSimple
{
get => ColorTools.GlobalSettings.ColorTransformationMethod == TransformationMethod.Vienot1999;
set => ColorTools.GlobalSettings.ColorTransformationMethod = value ? TransformationMethod.Vienot1999 : TransformationMethod.Brettel1997;
get
{
try
{
return ColorTools.GlobalSettings.ColorTransformationMethod == TransformationMethod.Vienot1999;
}
catch
{
return false;
}
}
set
{
try
{
ColorTools.GlobalSettings.ColorTransformationMethod = value ? TransformationMethod.Vienot1999 : TransformationMethod.Brettel1997;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.GlobalSettings.ColorTransformationMethod)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
/// If you are sure that the console supports true color, or if you want to change your terminal to a terminal that supports true color, change this value.
Expand Down Expand Up @@ -254,8 +335,28 @@ public string AccentBackgroundColor
/// </summary>
public bool UseConsoleColorPalette
{
get => ColorTools.GlobalSettings.UseTerminalPalette;
set => ColorTools.GlobalSettings.UseTerminalPalette = value;
get
{
try
{
return ColorTools.GlobalSettings.UseTerminalPalette;
}
catch
{
return true;
}
}
set
{
try
{
ColorTools.GlobalSettings.UseTerminalPalette = value;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.GlobalSettings.UseTerminalPalette)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
/// Whether to allow foreground color
Expand All @@ -265,8 +366,15 @@ public bool AllowForegroundColor
get => KernelColorTools.allowForeground;
set
{
KernelColorTools.allowForeground = value;
ColorTools.AllowForeground = KernelColorTools.allowForeground;
try
{
KernelColorTools.allowForeground = value;
ColorTools.AllowForeground = KernelColorTools.allowForeground;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.AllowForeground)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
Expand All @@ -277,8 +385,15 @@ public bool AllowBackgroundColor
get => KernelColorTools.allowBackground;
set
{
KernelColorTools.allowBackground = value;
ColorTools.AllowBackground = KernelColorTools.allowBackground;
try
{
KernelColorTools.allowBackground = value;
ColorTools.AllowBackground = KernelColorTools.allowBackground;
}
catch (Exception ex)
{
DebugWriter.WriteDebug(DebugLevel.E, $"Failed to enable/disable {nameof(ColorTools.AllowBackground)} [{value}]: {ex.Message}");
}
}
}
/// <summary>
Expand Down

0 comments on commit e67fb89

Please sign in to comment.