aboutsummaryrefslogtreecommitdiff
path: root/colors/cmd.ps1
blob: ee41ec1c95444aa2a044ca3bd662ccbdee176702 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function HexToDword {
  param (
    [Parameter(Mandatory, ValueFromPipeline,
      HelpMessage='Hex-formatted 24-bit RGB value to convert')]
    [ValidatePattern('^[0-9a-fA-F]{6}$')]
    [string]$Hex
  )
  $r = $Hex.Substring(0, 2).ToLower()
  $g = $Hex.Substring(2, 2).ToLower()
  $b = $Hex.Substring(4, 2).ToLower()
  return "dword:00$b$g$r"
}

function NameToTableIndex {
  param (
    [Parameter(Mandatory, ValueFromPipeline,
      HelpMessage='Starlight color name')]
    [ValidatePattern('^(br)?(black|blue|green|cyan|red|magenta|yellow|white)$')]
    [string]$Name
  )
  switch ($Name) {
    'black'     { 00 }
    'blue'      { 01 }
    'green'     { 02 }
    'cyan'      { 03 }
    'red'       { 04 }
    'magenta'   { 05 }
    'yellow'    { 06 }
    'white'     { 07 }
    'brblack'   { 08 }
    'brblue'    { 09 }
    'brgreen'   { 10 }
    'brcyan'    { 11 }
    'brred'     { 12 }
    'brmagenta' { 13 }
    'bryellow'  { 14 }
    'brwhite'   { 15 }
  }
}

# reasonable bg/fg defaults
$bg = 0
$fg = 7

Write-Output 'Windows Registry Editor Version 5.00'
Write-Output '[HKEY_CURRENT_USER\Console]'
Get-Content .\colors.sh | ForEach-Object {
  $Name, $Value = $_ -split '='
  try {
    if ($Name -eq 'background') { $bg = $(NameToTableIndex $Value.Substring(1)) }
    if ($Name -eq 'foreground') { $fg = $(NameToTableIndex $Value.Substring(1)) }
    Write-Output $('"ColorTable{0:d2}"={1}' -f $(NameToTableIndex $Name), $(HexToDword $Value))
  } catch {}
}
Write-Output $('"ScreenColors"=dword:000000{0:x}{1:x}' -f $bg, $fg)