encapsule console attributes in struct
This commit is contained in:
parent
3484e07089
commit
a247624e90
|
@ -11,11 +11,8 @@ namespace ColorTool
|
|||
public class ColorScheme
|
||||
{
|
||||
public uint[] colorTable = null;
|
||||
public uint? foreground = null;
|
||||
public uint? background = null;
|
||||
public ConsoleAttributes consoleAttributes;
|
||||
|
||||
public uint? popupForeground = null;
|
||||
public uint? popupBackground = null;
|
||||
|
||||
public int CalculateIndex(uint value) =>
|
||||
colorTable.Select((color, idx) => Tuple.Create(color, idx))
|
||||
|
@ -83,14 +80,14 @@ namespace ColorTool
|
|||
_dump($"Color[{i}]", colorTable[i]);
|
||||
}
|
||||
|
||||
if (foreground != null)
|
||||
if (consoleAttributes.foreground != null)
|
||||
{
|
||||
_dump("FG ", foreground.Value);
|
||||
_dump("FG ", consoleAttributes.foreground.Value);
|
||||
}
|
||||
|
||||
if (background != null)
|
||||
if (consoleAttributes.background != null)
|
||||
{
|
||||
_dump("BG ", background.Value);
|
||||
_dump("BG ", consoleAttributes.background.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
tools/ColorTool/ColorTool/ConsoleAttributes.cs
Normal file
17
tools/ColorTool/ColorTool/ConsoleAttributes.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
// Licensed under the terms described in the LICENSE file in the root of this project.
|
||||
//
|
||||
|
||||
namespace ColorTool
|
||||
{
|
||||
public struct ConsoleAttributes
|
||||
{
|
||||
public uint? foreground;
|
||||
public uint? background;
|
||||
|
||||
public uint? popupForeground;
|
||||
public uint? popupBackground;
|
||||
|
||||
}
|
||||
}
|
|
@ -154,7 +154,7 @@ namespace ColorTool
|
|||
|
||||
if (colorTable != null)
|
||||
{
|
||||
return new ColorScheme { colorTable = colorTable, background = backgroundColor, foreground = foregroundColor, popupBackground = popupBackgroundColor, popupForeground = popupForegroundColor };
|
||||
return new ColorScheme { colorTable = colorTable, consoleAttributes = new ConsoleAttributes { background = backgroundColor, foreground = foregroundColor, popupBackground = popupBackgroundColor, popupForeground = popupForegroundColor } };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace ColorTool
|
|||
}
|
||||
}
|
||||
|
||||
return new ColorScheme { colorTable = colorTable, background = screenBackground, foreground = screenForeground, popupBackground = popupBackground, popupForeground = popupForeground };
|
||||
return new ColorScheme { colorTable = colorTable, consoleAttributes = new ConsoleAttributes { background = screenBackground, foreground = screenForeground, popupBackground = popupBackground, popupForeground = popupForeground } };
|
||||
}
|
||||
catch (Exception /*e*/)
|
||||
{
|
||||
|
|
|
@ -370,16 +370,16 @@ namespace ColorTool
|
|||
{
|
||||
csbiex.ColorTable[i] = colorScheme.colorTable[i];
|
||||
}
|
||||
if (colorScheme.background != null && colorScheme.foreground != null)
|
||||
if (colorScheme.consoleAttributes.background != null && colorScheme.consoleAttributes.foreground != null)
|
||||
{
|
||||
int fgidx = colorScheme.CalculateIndex(colorScheme.foreground.Value);
|
||||
int bgidx = colorScheme.CalculateIndex(colorScheme.background.Value);
|
||||
int fgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.foreground.Value);
|
||||
int bgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.background.Value);
|
||||
csbiex.wAttributes = (ushort)(fgidx | (bgidx << 4));
|
||||
}
|
||||
if (colorScheme.popupBackground != null && colorScheme.popupForeground != null)
|
||||
if (colorScheme.consoleAttributes.popupBackground != null && colorScheme.consoleAttributes.popupForeground != null)
|
||||
{
|
||||
int fgidx = colorScheme.CalculateIndex(colorScheme.popupForeground.Value);
|
||||
int bgidx = colorScheme.CalculateIndex(colorScheme.popupBackground.Value);
|
||||
int fgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.popupForeground.Value);
|
||||
int bgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.popupBackground.Value);
|
||||
csbiex.wPopupAttributes = (ushort)(fgidx | (bgidx << 4));
|
||||
}
|
||||
SetConsoleScreenBufferInfoEx(hOut, ref csbiex);
|
||||
|
|
|
@ -135,7 +135,7 @@ namespace ColorTool
|
|||
return null;
|
||||
}
|
||||
|
||||
return new ColorScheme { colorTable = colorTable, foreground = fgColor, background = bgColor };
|
||||
return new ColorScheme { colorTable = colorTable, consoleAttributes = new ConsoleAttributes { foreground = fgColor, background = bgColor } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue