forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There aren't any user-facing changes in this commit, just pulling logic out of Program.cs. All that remains in Program.cs is command line parsing. - The functions that wrote to the registry, the console, and the virtual terminal (--xterm) are now in their own files, implementing the `IConsoleTarget` interface - Move the utility method UIntToColor into ColorScheme, where it can be used as an indexer, e.g. myColorScheme[i] returns a System.Drawing.Color - The "export to INI" functionality is now in a "SchemeWriters" namespace; Parsers are now in a "SchemeParsers" namespace - Printing the color table is now in the ColorTable class.
- Loading branch information
Showing
16 changed files
with
617 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
// | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the terms described in the LICENSE file in the root of this project. | ||
// | ||
|
||
using System; | ||
|
||
namespace ColorTool | ||
{ | ||
class ColorTable | ||
{ | ||
static int DARK_BLACK = 0; | ||
static int DARK_BLUE = 1; | ||
static int DARK_GREEN = 2; | ||
static int DARK_CYAN = 3; | ||
static int DARK_RED = 4; | ||
static int DARK_MAGENTA = 5; | ||
static int DARK_YELLOW = 6; | ||
static int DARK_WHITE = 7; | ||
static int BRIGHT_BLACK = 8; | ||
static int BRIGHT_BLUE = 9; | ||
static int BRIGHT_GREEN = 10; | ||
static int BRIGHT_CYAN = 11; | ||
static int BRIGHT_RED = 12; | ||
static int BRIGHT_MAGENTA = 13; | ||
static int BRIGHT_YELLOW = 14; | ||
static int BRIGHT_WHITE = 15; | ||
|
||
// This is the order of colors when output by the table. | ||
static int[] outputFgs = { | ||
BRIGHT_WHITE , | ||
DARK_BLACK , | ||
BRIGHT_BLACK , | ||
DARK_RED , | ||
BRIGHT_RED , | ||
DARK_GREEN , | ||
BRIGHT_GREEN , | ||
DARK_YELLOW , | ||
BRIGHT_YELLOW , | ||
DARK_BLUE , | ||
BRIGHT_BLUE , | ||
DARK_MAGENTA , | ||
BRIGHT_MAGENTA , | ||
DARK_CYAN , | ||
BRIGHT_CYAN , | ||
DARK_WHITE , | ||
BRIGHT_WHITE | ||
}; | ||
|
||
|
||
static int[] saneBgs = { | ||
DARK_BLACK , | ||
DARK_RED , | ||
DARK_GREEN , | ||
DARK_YELLOW , | ||
DARK_BLUE , | ||
DARK_MAGENTA , | ||
DARK_CYAN , | ||
DARK_WHITE | ||
}; | ||
|
||
|
||
public static void PrintTable() | ||
{ | ||
ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor)); | ||
// Save the current background and foreground colors. | ||
ConsoleColor currentBackground = Console.BackgroundColor; | ||
ConsoleColor currentForeground = Console.ForegroundColor; | ||
string test = " gYw "; | ||
string[] FGs = { | ||
"m", | ||
"1m", | ||
"30m", | ||
"1;30m", | ||
"31m", | ||
"1;31m", | ||
"32m", | ||
"1;32m", | ||
"33m", | ||
"1;33m", | ||
"34m", | ||
"1;34m", | ||
"35m", | ||
"1;35m", | ||
"36m", | ||
"1;36m", | ||
"37m", | ||
"1;37m" | ||
}; | ||
string[] BGs = { | ||
"m", | ||
"40m", | ||
"41m", | ||
"42m", | ||
"43m", | ||
"44m", | ||
"45m", | ||
"46m", | ||
"47m" | ||
}; | ||
|
||
Console.Write("\t"); | ||
for (int bg = 0; bg < BGs.Length; bg++) | ||
{ | ||
if (bg > 0) Console.Write(" "); | ||
Console.Write(" "); | ||
Console.Write(bg == 0 ? " " : BGs[bg]); | ||
Console.Write(" "); | ||
} | ||
Console.WriteLine(); | ||
|
||
for (int fg = 0; fg < FGs.Length; fg++) | ||
{ | ||
Console.ForegroundColor = currentForeground; | ||
Console.BackgroundColor = currentBackground; | ||
|
||
if (fg >= 0) Console.Write(FGs[fg] + "\t"); | ||
|
||
if (fg == 0) Console.ForegroundColor = currentForeground; | ||
else Console.ForegroundColor = colors[outputFgs[fg - 1]]; | ||
|
||
for (int bg = 0; bg < BGs.Length; bg++) | ||
{ | ||
if (bg > 0) Console.Write(" "); | ||
if (bg == 0) | ||
Console.BackgroundColor = currentBackground; | ||
else Console.BackgroundColor = colors[saneBgs[bg - 1]]; | ||
Console.Write(test); | ||
Console.BackgroundColor = currentBackground; | ||
} | ||
Console.Write("\n"); | ||
|
||
} | ||
Console.Write("\n"); | ||
|
||
// Reset foreground and background colors | ||
Console.ForegroundColor = currentForeground; | ||
Console.BackgroundColor = currentBackground; | ||
} | ||
|
||
public static void PrintTableWithVt() | ||
{ | ||
// Save the current background and foreground colors. | ||
string test = " gYw "; | ||
string[] FGs = { | ||
"m", | ||
"1m", | ||
"30m", | ||
"1;30m", | ||
"31m", | ||
"1;31m", | ||
"32m", | ||
"1;32m", | ||
"33m", | ||
"1;33m", | ||
"34m", | ||
"1;34m", | ||
"35m", | ||
"1;35m", | ||
"36m", | ||
"1;36m", | ||
"37m", | ||
"1;37m" | ||
}; | ||
string[] BGs = { | ||
"m", | ||
"40m", | ||
"41m", | ||
"42m", | ||
"43m", | ||
"44m", | ||
"45m", | ||
"46m", | ||
"47m" | ||
}; | ||
|
||
Console.Write("\t"); | ||
for (int bg = 0; bg < BGs.Length; bg++) | ||
{ | ||
if (bg > 0) Console.Write(" "); | ||
Console.Write(" "); | ||
Console.Write(bg == 0 ? " " : BGs[bg]); | ||
Console.Write(" "); | ||
} | ||
Console.WriteLine(); | ||
|
||
for (int fg = 0; fg < FGs.Length; fg++) | ||
{ | ||
Console.Write("\x1b[m"); | ||
|
||
if (fg >= 0) | ||
{ | ||
Console.Write(FGs[fg] + "\t"); | ||
} | ||
|
||
if (fg == 0) | ||
{ | ||
Console.Write("\x1b[39m"); | ||
} | ||
else | ||
{ | ||
Console.Write("\x1b[" + FGs[fg]); | ||
} | ||
|
||
for (int bg = 0; bg < BGs.Length; bg++) | ||
{ | ||
if (bg > 0) | ||
{ | ||
Console.Write(" "); | ||
} | ||
if (bg == 0) | ||
{ | ||
Console.Write("\x1b[49m"); | ||
} | ||
else | ||
{ | ||
Console.Write("\x1b[" + BGs[bg]); | ||
} | ||
|
||
Console.Write(test); | ||
Console.Write("\x1b[49m"); | ||
} | ||
Console.Write("\n"); | ||
|
||
} | ||
Console.Write("\n"); | ||
|
||
// Reset foreground and background colors | ||
Console.Write("\x1b[m"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tools/ColorTool/ColorTool/ConsoleTargets/CurrentConsoleTarget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the terms described in the LICENSE file in the root of this project. | ||
// | ||
|
||
using System; | ||
using static ColorTool.ConsoleAPI; | ||
|
||
namespace ColorTool.ConsoleTargets | ||
{ | ||
/// <summary> | ||
/// A console target that writes to the currently open console. | ||
/// </summary> | ||
class CurrentConsoleTarget : IConsoleTarget | ||
{ | ||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) | ||
{ | ||
CONSOLE_SCREEN_BUFFER_INFO_EX csbiex = CONSOLE_SCREEN_BUFFER_INFO_EX.Create(); | ||
IntPtr hOut = GetStdOutputHandle(); | ||
bool success = GetConsoleScreenBufferInfoEx(hOut, ref csbiex); | ||
if (!success) | ||
{ | ||
throw new InvalidOperationException("Could not obtain console screen buffer"); | ||
} | ||
|
||
csbiex.srWindow.Bottom++; | ||
for (int i = 0; i < 16; i++) | ||
{ | ||
csbiex.ColorTable[i] = colorScheme.colorTable[i]; | ||
} | ||
if (colorScheme.consoleAttributes.background != null && colorScheme.consoleAttributes.foreground != null) | ||
{ | ||
int fgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.foreground.Value); | ||
int bgidx = colorScheme.CalculateIndex(colorScheme.consoleAttributes.background.Value); | ||
csbiex.wAttributes = (ushort)(fgidx | (bgidx << 4)); | ||
} | ||
if (colorScheme.consoleAttributes.popupBackground != null && colorScheme.consoleAttributes.popupForeground != null) | ||
{ | ||
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); | ||
|
||
if (!quietMode) | ||
{ | ||
ColorTable.PrintTable(); | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tools/ColorTool/ColorTool/ConsoleTargets/DefaultConsoleTarget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the terms described in the LICENSE file in the root of this project. | ||
// | ||
|
||
using Microsoft.Win32; | ||
using System; | ||
|
||
namespace ColorTool.ConsoleTargets | ||
{ | ||
/// <summary> | ||
/// A console target that writes to the Windows registry to modify system defaults | ||
/// </summary> | ||
class DefaultConsoleTarget : IConsoleTarget | ||
{ | ||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode) | ||
{ | ||
//TODO | ||
RegistryKey consoleKey = Registry.CurrentUser.OpenSubKey("Console", true); | ||
for (int i = 0; i < colorScheme.colorTable.Length; i++) | ||
{ | ||
string valueName = "ColorTable" + (i < 10 ? "0" : "") + i; | ||
consoleKey.SetValue(valueName, colorScheme.colorTable[i], RegistryValueKind.DWord); | ||
} | ||
Console.WriteLine(Resources.WroteToDefaults); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tools/ColorTool/ColorTool/ConsoleTargets/IConsoleTarget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the terms described in the LICENSE file in the root of this project. | ||
// | ||
|
||
namespace ColorTool.ConsoleTargets | ||
{ | ||
/// <summary> | ||
/// A console that can have a color scheme applied to it. | ||
/// </summary> | ||
interface IConsoleTarget | ||
{ | ||
void ApplyColorScheme(ColorScheme colorScheme, bool quietMode); | ||
} | ||
} |
Oops, something went wrong.