Last active
February 12, 2021 04:37
-
-
Save tylerszabo/eeaea83d05889191efcf7da0853ab365 to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
Output Windows Terminal color scheme JSON from a ColorTool .INI scheme | |
.DESCRIPTION | |
Until a new release of ColorTool that contains the update to output Windows Terminal JSON schemes it'll either need to be built locally or .INI schemes converted. This script accomplishes the convesrion of ColorTool .INI schemes for Windows Termianl. | |
.PARAMETER Path | |
Path to a ColorTool scheme .INI file | |
.LINK | |
https://github.com/microsoft/terminal | |
.LINK | |
https://github.com/microsoft/terminal/tree/main/src/tools/ColorTool | |
.LINK | |
https://github.com/microsoft/terminal/commit/04e808fd0a5e60821af02a6dcc284e816521abf9 | |
.NOTES | |
Author: Tyler Szabo | |
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <https://unlicense.org> | |
#> | |
[CmdletBinding(DefaultParameterSetName = "PipelineByProperty")] | |
Param ( | |
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True, ParameterSetName = "PipelineByProperty")] | |
[string[]] | |
$Path | |
) | |
$Script:ColorMapping = @{ | |
"DARK_BLACK" = "black"; | |
"DARK_BLUE" = "blue"; | |
"DARK_GREEN" = "green"; | |
"DARK_CYAN" = "cyan"; | |
"DARK_RED" = "red"; | |
"DARK_MAGENTA" = "purple"; | |
"DARK_YELLOW" = "yellow"; | |
"DARK_WHITE" = "white"; | |
"BRIGHT_BLACK" = "brightBlack"; | |
"BRIGHT_BLUE" = "brightBlue"; | |
"BRIGHT_GREEN" = "brightGreen"; | |
"BRIGHT_CYAN" = "brightCyan"; | |
"BRIGHT_RED" = "brightRed"; | |
"BRIGHT_MAGENTA" = "brightPurple"; | |
"BRIGHT_YELLOW" = "brightYellow"; | |
"BRIGHT_WHITE" = "brightWhite"; | |
} | |
$Properties = [ordered]@{ | |
# Based on Campbell | |
"name" = "Unnamed"; | |
"cursorColor" = ""; | |
"selectionBackground" = ""; | |
"background" = "#0C0C0C"; | |
"foreground" = "#CCCCCC"; | |
"black" = "#0C0C0C"; | |
"blue" = "#0037DA"; | |
"cyan" = "#3A96DD"; | |
"green" = "#13A10E"; | |
"purple" = "#881798"; | |
"red" = "#C50F1F"; | |
"white" = "#CCCCCC"; | |
"yellow" = "#C19C00"; | |
"brightBlack" = "#767676"; | |
"brightBlue" = "#3B78FF"; | |
"brightCyan" = "#61D6D6"; | |
"brightGreen" = "#16C60C"; | |
"brightPurple" = "#B4009E"; | |
"brightRed" = "#E74856"; | |
"brightWhite" = "#F2F2F2"; | |
"brightYellow" = "#F9F1A5" | |
} | |
$ParsedColors = @{} | |
$FGString = "" | |
$BGString = "" | |
$SelectFGString = "" | |
$SelectBGString = "" | |
$Section = "" | |
$Path | ForEach-Object { | |
$Content = (Get-Content -Path $_) | |
$Content | ForEach-Object { | |
If ($_ -Match "^\s*(\[[^\]]+\])") { | |
$Section = $Matches[1] | |
} ElseIf ($Section -Eq "[table]") { | |
If ($_ -Match "([A-Z_]*)\s*=\s*([0-9]*),([0-9]*),([0-9]*)") { | |
$HexRGB = "#$(([int]$Matches[2]).ToString("X02"))$(([int]$Matches[3]).ToString("X02"))$(([int]$Matches[4]).ToString("X02"))" | |
$ParsedColors[$Matches[1]] = $HexRGB | |
$Properties[$ColorMapping[$Matches[1]]] = $hexRGB | |
} | |
} ElseIf ($Section -Eq "[screen]") { | |
If ($_ -Match "FOREGROUND\s*=\s*([A-Z_]+)") { | |
$FGString = $Matches[1] | |
} ElseIf ($_ -Match "BACKGROUND\s*=\s*([A-Z_]+)") { | |
$BGString = $Matches[1] | |
} | |
} ElseIf ($Section -Eq "[popup]") { | |
If ($_ -Match "FOREGROUND\s*=\s*([A-Z_]+)") { | |
$SelectFGString = $Matches[1] | |
} ElseIf ($_ -Match "BACKGROUND\s*=\s*([A-Z_]+)") { | |
$SelectBGString = $Matches[1] | |
} | |
} ElseIf ($Section -Eq "[info]") { | |
If ($_ -Match "name\s*=\s*(.+)\s*$") { | |
$Properties["name"] = $Matches[1] | |
} | |
} | |
} | |
} | |
$Properties["background"] = $ParsedColors[$BGString] | |
$Properties["foreground"] = $ParsedColors[$FGString] | |
$Properties["cursorColor"] = $ParsedColors[$SelectFGString] | |
$Properties["selectionBackground"] = $ParsedColors[$SelectBGString] | |
$Properties | ConvertTo-Json | Write-Output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment