mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 18:43:54 -06:00
Colortool: improve color table. (#12089)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request - add suport for light backgrounds - make color tool use 90-97 and 100-107 sequences for fg/bg - fix loops stop condition <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments additional improvements that I've seen while working on #12087 <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
This commit is contained in:
parent
d5b177dc33
commit
95a79c2262
1
.github/actions/spelling/allow/allow.txt
vendored
1
.github/actions/spelling/allow/allow.txt
vendored
@ -82,3 +82,4 @@ We'd
|
||||
wildcards
|
||||
yeru
|
||||
zhe
|
||||
allcolors
|
||||
|
||||
@ -31,9 +31,8 @@ namespace ColorTool
|
||||
private const int BrightWhite = 15;
|
||||
|
||||
// This is the order of colors when output by the table.
|
||||
private static readonly IReadOnlyList<int> Foregrounds = new[]
|
||||
private static readonly IReadOnlyList<int> TableColors = new[]
|
||||
{
|
||||
BrightWhite,
|
||||
DarkBlack,
|
||||
BrightBlack,
|
||||
DarkRed,
|
||||
@ -52,88 +51,91 @@ namespace ColorTool
|
||||
BrightWhite
|
||||
};
|
||||
|
||||
private static readonly IReadOnlyList<int> Backgrounds = new[]
|
||||
{
|
||||
DarkBlack,
|
||||
DarkRed,
|
||||
DarkGreen,
|
||||
DarkYellow,
|
||||
DarkBlue,
|
||||
DarkMagenta,
|
||||
DarkCyan,
|
||||
DarkWhite
|
||||
};
|
||||
|
||||
private const string TestText = " gYw ";
|
||||
|
||||
private static readonly IReadOnlyList<string> AnsiForegroundSequences = new[]
|
||||
{
|
||||
"m",
|
||||
"1m",
|
||||
"30m",
|
||||
"1;30m",
|
||||
"90m",
|
||||
"31m",
|
||||
"1;31m",
|
||||
"91m",
|
||||
"32m",
|
||||
"1;32m",
|
||||
"92m",
|
||||
"33m",
|
||||
"1;33m",
|
||||
"93m",
|
||||
"34m",
|
||||
"1;34m",
|
||||
"94m",
|
||||
"35m",
|
||||
"1;35m",
|
||||
"95m",
|
||||
"36m",
|
||||
"1;36m",
|
||||
"96m",
|
||||
"37m",
|
||||
"1;37m"
|
||||
"97m"
|
||||
};
|
||||
|
||||
private static readonly IReadOnlyList<string> AnsiBackgroundSequences = new[]
|
||||
{
|
||||
"m",
|
||||
"40m",
|
||||
"100m",
|
||||
"41m",
|
||||
"101m",
|
||||
"42m",
|
||||
"102m",
|
||||
"43m",
|
||||
"103m",
|
||||
"44m",
|
||||
"104m",
|
||||
"45m",
|
||||
"105m",
|
||||
"46m",
|
||||
"47m"
|
||||
"106m",
|
||||
"47m",
|
||||
"107m"
|
||||
};
|
||||
|
||||
public static void PrintTable()
|
||||
private const string AnsiDefaultFg = "39m";
|
||||
private const string AnsiDefaultBg = "49m";
|
||||
|
||||
public static void PrintTable(bool compact)
|
||||
{
|
||||
string TestText = compact ? " gYw " : " gYw ";
|
||||
ConsoleColor[] colors = (ConsoleColor[])ConsoleColor.GetValues(typeof(ConsoleColor));
|
||||
// Save the current background and foreground colors.
|
||||
ConsoleColor currentBackground = Console.BackgroundColor;
|
||||
ConsoleColor currentForeground = Console.ForegroundColor;
|
||||
|
||||
Console.Write("\t");
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++)
|
||||
// first column
|
||||
Console.Write("\t ");
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(AnsiDefaultBg);
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(" ");
|
||||
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact))
|
||||
{
|
||||
if (bg > 0) Console.Write(" ");
|
||||
Console.Write(" ");
|
||||
Console.Write(bg == 0 ? " " : AnsiBackgroundSequences[bg]);
|
||||
Console.Write(" ");
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(AnsiBackgroundSequences[bg]);
|
||||
if (compact) Console.Write(" ");
|
||||
if (AnsiBackgroundSequences[bg].Length == 3) Console.Write(" ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
for (int fg = 0; fg < AnsiForegroundSequences.Count; fg++)
|
||||
for (int fg = 0; fg <= TableColors.Count && fg <= AnsiForegroundSequences.Count; fg++)
|
||||
{
|
||||
Console.ForegroundColor = currentForeground;
|
||||
Console.BackgroundColor = currentBackground;
|
||||
|
||||
if (fg >= 0) Console.Write(AnsiForegroundSequences[fg] + "\t");
|
||||
Console.Write(fg == 0 ? AnsiDefaultFg : AnsiForegroundSequences[fg - 1]);
|
||||
Console.Write("\t");
|
||||
|
||||
if (fg == 0) Console.ForegroundColor = currentForeground;
|
||||
else Console.ForegroundColor = colors[Foregrounds[fg - 1]];
|
||||
else Console.ForegroundColor = colors[TableColors[fg - 1]];
|
||||
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++)
|
||||
for (int bg = 0; bg <= TableColors.Count; bg += 1 + Convert.ToUInt16(compact))
|
||||
{
|
||||
if (bg > 0) Console.Write(" ");
|
||||
if (bg == 0)
|
||||
Console.BackgroundColor = currentBackground;
|
||||
else Console.BackgroundColor = colors[Backgrounds[bg - 1]];
|
||||
else Console.BackgroundColor = colors[TableColors[bg - (1 + Convert.ToUInt16(compact))]];
|
||||
Console.Write(TestText);
|
||||
Console.BackgroundColor = currentBackground;
|
||||
}
|
||||
@ -146,50 +148,41 @@ namespace ColorTool
|
||||
Console.BackgroundColor = currentBackground;
|
||||
}
|
||||
|
||||
public static void PrintTableWithVt()
|
||||
public static void PrintTableWithVt(bool compact)
|
||||
{
|
||||
Console.Write("\t");
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++)
|
||||
string TestText = compact ? " gYw " : " gYw ";
|
||||
// first column
|
||||
Console.Write("\t ");
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(AnsiDefaultBg);
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(" ");
|
||||
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact))
|
||||
{
|
||||
if (bg > 0) Console.Write(" ");
|
||||
Console.Write(" ");
|
||||
Console.Write(bg == 0 ? " " : AnsiBackgroundSequences[bg]);
|
||||
Console.Write(" ");
|
||||
if (compact) Console.Write(" ");
|
||||
Console.Write(AnsiBackgroundSequences[bg]);
|
||||
if (compact) Console.Write(" ");
|
||||
if (AnsiBackgroundSequences[bg].Length == 3) Console.Write(" ");
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
for (int fg = 0; fg < AnsiForegroundSequences.Count; fg++)
|
||||
for (int fg = 0; fg <= AnsiForegroundSequences.Count; fg++)
|
||||
{
|
||||
Console.Write("\x1b[m");
|
||||
|
||||
if (fg >= 0)
|
||||
{
|
||||
Console.Write(AnsiForegroundSequences[fg] + "\t");
|
||||
}
|
||||
Console.Write(fg == 0 ? AnsiDefaultFg : AnsiForegroundSequences[fg - 1]);
|
||||
Console.Write("\t");
|
||||
|
||||
if (fg == 0)
|
||||
{
|
||||
Console.Write("\x1b[39m");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("\x1b[" + AnsiForegroundSequences[fg]);
|
||||
}
|
||||
if (fg == 0) Console.Write("\x1b[" + AnsiDefaultFg);
|
||||
else Console.Write("\x1b[" + AnsiForegroundSequences[fg - 1]);
|
||||
|
||||
for (int bg = 0; bg < AnsiBackgroundSequences.Count; bg++)
|
||||
for (int bg = 0; bg <= AnsiBackgroundSequences.Count; bg += 1 + Convert.ToUInt16(compact))
|
||||
{
|
||||
if (bg > 0)
|
||||
{
|
||||
Console.Write(" ");
|
||||
}
|
||||
if (bg == 0)
|
||||
{
|
||||
Console.Write("\x1b[49m");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("\x1b[" + AnsiBackgroundSequences[bg]);
|
||||
}
|
||||
if (bg != 0) Console.Write(" ");
|
||||
if (bg == 0) Console.Write("\x1b[" + AnsiDefaultBg);
|
||||
else Console.Write("\x1b[" + AnsiBackgroundSequences[bg - (1 + Convert.ToUInt16(compact))]);
|
||||
|
||||
Console.Write(TestText);
|
||||
Console.Write("\x1b[49m");
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ColorTool.ConsoleTargets
|
||||
/// </summary>
|
||||
class CurrentConsoleTarget : IConsoleTarget
|
||||
{
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode)
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO_EX csbiex = CONSOLE_SCREEN_BUFFER_INFO_EX.Create();
|
||||
IntPtr hOut = GetStdOutputHandle();
|
||||
@ -40,7 +40,7 @@ namespace ColorTool.ConsoleTargets
|
||||
|
||||
if (!quietMode)
|
||||
{
|
||||
ColorTable.PrintTable();
|
||||
ColorTable.PrintTable(compactColortable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace ColorTool.ConsoleTargets
|
||||
/// </summary>
|
||||
class DefaultConsoleTarget : IConsoleTarget
|
||||
{
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode)
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable)
|
||||
{
|
||||
RegistryKey consoleKey = Registry.CurrentUser.OpenSubKey("Console", true);
|
||||
for (int i = 0; i < colorScheme.ColorTable.Length; i++)
|
||||
|
||||
@ -10,6 +10,6 @@ namespace ColorTool.ConsoleTargets
|
||||
/// </summary>
|
||||
interface IConsoleTarget
|
||||
{
|
||||
void ApplyColorScheme(ColorScheme colorScheme, bool quietMode);
|
||||
void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ namespace ColorTool.ConsoleTargets
|
||||
{
|
||||
class TerminalSchemeConsoleTarget : IConsoleTarget
|
||||
{
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode)
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable)
|
||||
{
|
||||
Console.WriteLine("Copy and paste the following text into the schemes array of your Windows Terminal settings.json file to add this color scheme. (Don't forget to add a comma separator after the previous scheme.)");
|
||||
Console.WriteLine("{");
|
||||
|
||||
@ -36,7 +36,7 @@ namespace ColorTool.ConsoleTargets
|
||||
8+7, // Bright White
|
||||
};
|
||||
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode)
|
||||
public void ApplyColorScheme(ColorScheme colorScheme, bool quietMode, bool compactColortable)
|
||||
{
|
||||
Program.DoInVTMode(() =>
|
||||
{
|
||||
@ -58,7 +58,6 @@ namespace ColorTool.ConsoleTargets
|
||||
string s = $"\x1b]12;rgb:{color.R:X2}/{color.G:X2}/{color.B:X2}\x1b\\";
|
||||
Console.Write(s);
|
||||
}
|
||||
|
||||
for (int i = 0; i < colorScheme.ColorTable.Length; i++)
|
||||
{
|
||||
int vtIndex = VirtualTerminalIndices[i];
|
||||
@ -69,7 +68,7 @@ namespace ColorTool.ConsoleTargets
|
||||
|
||||
if (!quietMode)
|
||||
{
|
||||
ColorTable.PrintTableWithVt();
|
||||
ColorTable.PrintTableWithVt(compactColortable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
//
|
||||
|
||||
using ColorTool.ConsoleTargets;
|
||||
using ColorTool.SchemeWriters;
|
||||
using static ColorTool.ConsoleAPI;
|
||||
using ColorTool.SchemeWriters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -20,6 +20,8 @@ namespace ColorTool
|
||||
private static bool setProperties = true;
|
||||
private static bool setUnixStyle = false;
|
||||
private static bool setTerminalStyle = false;
|
||||
private static bool compactTableStyle = true;
|
||||
private static bool printCurrent = false;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@ -39,8 +41,8 @@ namespace ColorTool
|
||||
return;
|
||||
case "-c":
|
||||
case "--current":
|
||||
ColorTable.PrintTable();
|
||||
return;
|
||||
printCurrent = true;
|
||||
break;
|
||||
case "-l":
|
||||
case "--location":
|
||||
SchemeManager.PrintSchemesDirectory();
|
||||
@ -66,36 +68,46 @@ namespace ColorTool
|
||||
return;
|
||||
case "-e":
|
||||
case "--errors":
|
||||
reportErrors = true;
|
||||
reportErrors = true;
|
||||
break;
|
||||
case "-q":
|
||||
case "--quiet":
|
||||
quietMode = true;
|
||||
quietMode = true;
|
||||
break;
|
||||
case "-d":
|
||||
case "--defaults":
|
||||
setDefaults = true;
|
||||
setProperties = false;
|
||||
setDefaults = true;
|
||||
setProperties = false;
|
||||
break;
|
||||
case "-b":
|
||||
case "--both":
|
||||
setDefaults = true;
|
||||
setProperties = true;
|
||||
setDefaults = true;
|
||||
setProperties = true;
|
||||
break;
|
||||
case "-x":
|
||||
case "--xterm":
|
||||
setUnixStyle = true;
|
||||
setProperties = true;
|
||||
setUnixStyle = true;
|
||||
setProperties = true;
|
||||
break;
|
||||
case "-a":
|
||||
case "--allcolors":
|
||||
compactTableStyle = false;
|
||||
break;
|
||||
case "-t":
|
||||
case "--terminal":
|
||||
setTerminalStyle = true;
|
||||
setProperties = true;
|
||||
setProperties = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (printCurrent)
|
||||
{
|
||||
if (setUnixStyle) DoInVTMode(() => ColorTable.PrintTableWithVt(compactTableStyle));
|
||||
else ColorTable.PrintTable(compactTableStyle);
|
||||
return;
|
||||
}
|
||||
|
||||
string schemeName = args[args.Length - 1];
|
||||
|
||||
@ -109,7 +121,7 @@ namespace ColorTool
|
||||
|
||||
foreach (var target in GetConsoleTargets())
|
||||
{
|
||||
target.ApplyColorScheme(colorScheme, quietMode);
|
||||
target.ApplyColorScheme(colorScheme, quietMode, compactTableStyle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
@ -121,8 +121,8 @@
|
||||
<value>Error loading ini file "{0}"</value>
|
||||
</data>
|
||||
<data name="IniParseError" xml:space="preserve">
|
||||
<value>Error loading ini file "{0}"
|
||||
for key "{1}"
|
||||
<value>Error loading ini file "{0}"
|
||||
for key "{1}"
|
||||
the value "{2}" is invalid</value>
|
||||
</data>
|
||||
<data name="InvalidColor" xml:space="preserve">
|
||||
@ -160,7 +160,7 @@ Parameters:
|
||||
Functions:
|
||||
You may specify only one of the following switches each time you invoke ColorTool. Any additional switches
|
||||
before or after the first one of them will be ignored.
|
||||
|
||||
|
||||
-?, --help : Display this help message
|
||||
-c, --current : Print the color table for the currently applied scheme
|
||||
-v, --version : Display the version number
|
||||
@ -180,11 +180,11 @@ Options:
|
||||
-x, --xterm : Set the colors using VT sequences. Used for setting the colors in WSL.
|
||||
Only works in Windows versions >= 17048.
|
||||
-t, --terminal : Output the colors in JSON format for copying into a Windows Terminal settings file.
|
||||
|
||||
-a, --allcolors: Output extended color table. best for >110 column terminals
|
||||
Available importers:
|
||||
{0}</value>
|
||||
</data>
|
||||
<data name="WroteToDefaults" xml:space="preserve">
|
||||
<value>Wrote selected scheme to the defaults.</value>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
||||
|
||||
@ -45,6 +45,7 @@ Options:
|
||||
-x, --xterm : Set the colors using VT sequences. Used for setting the colors in WSL.
|
||||
Only works in Windows versions >= 17048.
|
||||
-t, --terminal : Output the colors in JSON format for copying into a Windows Terminal settings file.
|
||||
-a, --allcolors: Output extended color table. best for >110 column terminals
|
||||
```
|
||||
|
||||
## Included Schemes
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user