diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
index 0cf0c4497..3cdfd523e 100644
--- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
@@ -40,7 +40,7 @@ namespace Terminal.Gui {
}
static bool sync = false;
- public override void AddRune (Rune rune)
+ public override void AddRune (Rune rune)
{
if (Clip.Contains (ccol, crow)) {
if (needMove) {
@@ -91,7 +91,14 @@ namespace Terminal.Gui {
}
public override void UpdateScreen () => window.redrawwin ();
- public override void SetAttribute (Attribute c) => Curses.attrset (c.value);
+
+ int currentAttribute;
+
+ public override void SetAttribute (Attribute c) {
+ currentAttribute = c.Value;
+ Curses.attrset (currentAttribute);
+ }
+
public Curses.Window window;
static short last_color_pair = 16;
@@ -105,7 +112,11 @@ namespace Terminal.Gui {
public static Attribute MakeColor (short foreground, short background)
{
Curses.InitColorPair (++last_color_pair, foreground, background);
- return new Attribute () { value = Curses.ColorPair (last_color_pair) };
+ return new Attribute (
+ value: Curses.ColorPair (last_color_pair),
+ foreground: (Color)foreground,
+ background: (Color)background
+ );
}
int [,] colorPairs = new int [16, 16];
@@ -848,6 +859,11 @@ namespace Terminal.Gui {
//mouseGrabbed = false;
//Curses.mouseinterval (lastMouseInterval);
}
+
+ public override Attribute GetAttribute ()
+ {
+ return currentAttribute;
+ }
}
internal static class Platform {
diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
index c5a611fe7..8a443133e 100644
--- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
@@ -113,7 +113,11 @@ namespace Terminal.Gui {
static Attribute MakeColor (ConsoleColor f, ConsoleColor b)
{
// Encode the colors into the int value.
- return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) };
+ return new Attribute (
+ value: ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff),
+ foreground: (Color)f,
+ background: (Color)b
+ );
}
public override void Init (Action terminalResized)
@@ -249,7 +253,7 @@ namespace Terminal.Gui {
int currentAttribute;
public override void SetAttribute (Attribute c)
{
- currentAttribute = c.value;
+ currentAttribute = c.Value;
}
Key MapKey (ConsoleKeyInfo keyInfo)
@@ -390,9 +394,14 @@ namespace Terminal.Gui {
};
}
+ public override Attribute GetAttribute ()
+ {
+ return currentAttribute;
+ }
+
+ #region Unused
public override void SetColors (ConsoleColor foreground, ConsoleColor background)
{
- throw new NotImplementedException ();
}
public override void SetColors (short foregroundColorId, short backgroundColorId)
@@ -407,6 +416,7 @@ namespace Terminal.Gui {
public override void UncookMouse ()
{
}
+ #endregion
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}
\ No newline at end of file
diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs
index 53997351f..0e65c8022 100644
--- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs
@@ -95,7 +95,11 @@ namespace Terminal.Gui {
static Attribute MakeColor (ConsoleColor f, ConsoleColor b)
{
// Encode the colors into the int value.
- return new Attribute () { value = ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff) };
+ return new Attribute (
+ value: ((((int)f) & 0xffff) << 16) | (((int)b) & 0xffff),
+ foreground: (Color)f,
+ background: (Color)b
+ );
}
bool isWinPlatform;
@@ -319,7 +323,7 @@ namespace Terminal.Gui {
int currentAttribute;
public override void SetAttribute (Attribute c)
{
- currentAttribute = c.value;
+ currentAttribute = c.Value;
}
Key MapKey (ConsoleKeyInfo keyInfo)
@@ -492,6 +496,12 @@ namespace Terminal.Gui {
};
}
+ public override Attribute GetAttribute ()
+ {
+ return currentAttribute;
+ }
+
+ #region Unused
public override void SetColors (ConsoleColor foreground, ConsoleColor background)
{
}
@@ -507,6 +517,7 @@ namespace Terminal.Gui {
public override void UncookMouse ()
{
}
+ #endregion
//
// These are for the .NET driver, but running natively on Windows, wont run
diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
index abc70c0a1..bf078bc30 100644
--- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
+++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
@@ -1236,17 +1236,17 @@ namespace Terminal.Gui {
public override void SetAttribute (Attribute c)
{
- currentAttribute = c.value;
+ currentAttribute = c.Value;
}
Attribute MakeColor (ConsoleColor f, ConsoleColor b)
{
// Encode the colors into the int value.
- return new Attribute () {
- value = ((int)f | (int)b << 4),
- foreground = (Color)f,
- background = (Color)b
- };
+ return new Attribute (
+ value: ((int)f | (int)b << 4),
+ foreground: (Color)f,
+ background: (Color)b
+ );
}
public override Attribute MakeAttribute (Color fore, Color back)
@@ -1312,6 +1312,11 @@ namespace Terminal.Gui {
winConsole.Cleanup ();
}
+ public override Attribute GetAttribute ()
+ {
+ return currentAttribute;
+ }
+
#region Unused
public override void SetColors (ConsoleColor foreground, ConsoleColor background)
{
diff --git a/Terminal.Gui/Core/ConsoleDriver.cs b/Terminal.Gui/Core/ConsoleDriver.cs
index 1f618e5d7..7be26f4a6 100644
--- a/Terminal.Gui/Core/ConsoleDriver.cs
+++ b/Terminal.Gui/Core/ConsoleDriver.cs
@@ -61,7 +61,7 @@ namespace Terminal.Gui {
///
BrightGreen,
///
- /// The brigh cyan color.
+ /// The bright cyan color.
///
BrighCyan,
///
@@ -91,9 +91,18 @@ namespace Terminal.Gui {
/// class to define color schemes that can be used in your application.
///
public struct Attribute {
- internal int value;
- internal Color foreground;
- internal Color background;
+ ///
+ /// The color attribute value.
+ ///
+ public int Value { get; }
+ ///
+ /// The foreground color.
+ ///
+ public Color Foreground { get; }
+ ///
+ /// The background color.
+ ///
+ public Color Background { get; }
///
/// Initializes a new instance of the struct.
@@ -103,9 +112,9 @@ namespace Terminal.Gui {
/// Background
public Attribute (int value, Color foreground = new Color (), Color background = new Color ())
{
- this.value = value;
- this.foreground = foreground;
- this.background = background;
+ Value = value;
+ Foreground = foreground;
+ Background = background;
}
///
@@ -115,9 +124,9 @@ namespace Terminal.Gui {
/// Background
public Attribute (Color foreground = new Color (), Color background = new Color ())
{
- this.value = value = ((int)foreground | (int)background << 4);
- this.foreground = foreground;
- this.background = background;
+ Value = (int)foreground | ((int)background << 4);
+ Foreground = foreground;
+ Background = background;
}
///
@@ -125,7 +134,7 @@ namespace Terminal.Gui {
///
/// The integer value stored in the attribute.
/// The attribute to convert
- public static implicit operator int (Attribute c) => c.value;
+ public static implicit operator int (Attribute c) => c.Value;
///
/// Implicitly convert an integer value into an
@@ -146,6 +155,17 @@ namespace Terminal.Gui {
throw new InvalidOperationException ("The Application has not been initialized");
return Application.Driver.MakeAttribute (foreground, background);
}
+
+ ///
+ /// Gets the current from the driver.
+ ///
+ /// The current attribute.
+ public static Attribute Get ()
+ {
+ if (Application.Driver == null)
+ throw new InvalidOperationException ("The Application has not been initialized");
+ return Application.Driver.GetAttribute ();
+ }
}
///
@@ -201,18 +221,18 @@ namespace Terminal.Gui {
case "TopLevel":
switch (callerMemberName) {
case "Normal":
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
break;
case "Focus":
- HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background);
+ HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
break;
case "HotNormal":
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background);
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
break;
case "HotFocus":
- HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background);
- if (Focus.foreground != attribute.background)
- Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
+ if (Focus.Foreground != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
break;
}
break;
@@ -220,19 +240,19 @@ namespace Terminal.Gui {
case "Base":
switch (callerMemberName) {
case "Normal":
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
break;
case "Focus":
- HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background);
+ HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
break;
case "HotNormal":
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background);
- Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background);
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
+ Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
break;
case "HotFocus":
- HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background);
- if (Focus.foreground != attribute.background)
- Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
+ if (Focus.Foreground != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
break;
}
break;
@@ -240,57 +260,56 @@ namespace Terminal.Gui {
case "Menu":
switch (callerMemberName) {
case "Normal":
- if (Focus.background != attribute.background)
- Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background);
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
- Disabled = Application.Driver.MakeAttribute (Disabled.foreground, attribute.background);
+ if (Focus.Background != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
+ Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
break;
case "Focus":
- Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background);
- HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background);
+ Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
+ HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
break;
case "HotNormal":
- if (Focus.background != attribute.background)
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background);
- Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background);
- Disabled = Application.Driver.MakeAttribute (Disabled.foreground, attribute.background);
+ if (Focus.Background != attribute.Background)
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
+ Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
+ Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
break;
case "HotFocus":
- HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background);
- if (Focus.foreground != attribute.background)
- Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
+ if (Focus.Foreground != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
break;
case "Disabled":
- if (Focus.background != attribute.background)
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background);
- Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background);
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
+ if (Focus.Background != attribute.Background)
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
+ Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
break;
-
}
break;
case "Dialog":
switch (callerMemberName) {
case "Normal":
- if (Focus.background != attribute.background)
- Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background);
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
+ if (Focus.Background != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
break;
case "Focus":
- Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background);
- HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background);
+ Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
+ HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
break;
case "HotNormal":
- if (Focus.background != attribute.background)
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background);
- if (Normal.foreground != attribute.background)
- Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background);
+ if (Focus.Background != attribute.Background)
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
+ if (Normal.Foreground != attribute.Background)
+ Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
break;
case "HotFocus":
- HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background);
- if (Focus.foreground != attribute.background)
- Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
+ if (Focus.Foreground != attribute.Background)
+ Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
break;
}
break;
@@ -298,17 +317,16 @@ namespace Terminal.Gui {
case "Error":
switch (callerMemberName) {
case "Normal":
- HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background);
- HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background);
+ HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
+ HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
break;
case "HotNormal":
case "HotFocus":
- HotFocus = Application.Driver.MakeAttribute (attribute.foreground, attribute.background);
- Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background);
+ HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, attribute.Background);
+ Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
break;
}
break;
-
}
preparingScheme = false;
return attribute;
@@ -383,7 +401,7 @@ namespace Terminal.Gui {
public static class Colors {
static Colors ()
{
- // Use reflection to dynamically create the default set of ColorSchemes from the list defiined
+ // Use reflection to dynamically create the default set of ColorSchemes from the list defined
// by the class.
ColorSchemes = typeof (Colors).GetProperties ()
.Where (p => p.PropertyType == typeof (ColorScheme))
@@ -661,7 +679,7 @@ namespace Terminal.Gui {
/// Number of rows to pad on the top (if 0 the border and title will not appear on the top).
/// Number of columns to pad on the right (if 0 the border will not appear on the right).
/// Number of rows to pad on the bottom (if 0 the border will not appear on the bottom).
- /// Not yet immplemented.
+ /// Not yet implemented.
///
public virtual void DrawWindowTitle (Rect region, ustring title, int paddingLeft, int paddingTop, int paddingRight, int paddingBottom, TextAlignment textAlignment = TextAlignment.Left)
{
@@ -676,7 +694,7 @@ namespace Terminal.Gui {
}
///
- /// Enables diagnostic funcions
+ /// Enables diagnostic functions
///
[Flags]
public enum DiagnosticFlags : uint {
@@ -867,7 +885,7 @@ namespace Terminal.Gui {
/// Screen relative region where the frame will be drawn.
/// Padding to add on the sides.
/// If set to true it will clear the contents with the current color, otherwise the contents will be left untouched.
- /// This API has been superceded by .
+ /// This API has been supersede by .
/// This API is equivalent to calling DrawWindowFrame(Rect, p - 1, p - 1, p - 1, p - 1). In other words,
/// A padding value of 0 means there is actually a one cell border.
///
@@ -1053,5 +1071,11 @@ namespace Terminal.Gui {
/// Background.
///
public abstract Attribute MakeAttribute (Color fore, Color back);
+
+ ///
+ /// Gets the current .
+ ///
+ /// The current attribute.
+ public abstract Attribute GetAttribute ();
}
}