10

目前从 Console Colors 中选择的 16 种颜色对我来说不是正确的选择。我想使用这些颜色更深的变体作为背景。

我绝对可以使用 UI 设置这些并在那里更改 RGB 值。

选择蓝色并将值更改为 65

例如,我可以在 RGB 部分选择深蓝色并为蓝色选择 65(默认为 128)。有人可以告诉我如何以编程方式执行此操作。

就像是:

(Get-Host).UI.RawUI.BackgroundColor=DarkBlue

但有额外的选择。

4

3 回答 3

11

Lee Holmes 的这篇旧文章解释了如何将颜色更改为您想要的任何值。您必须更改注册表 - http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/

Push-Location 
Set-Location HKCU:\Console 
New-Item ".\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe" 
Set-Location ".\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe"

New-ItemProperty . ColorTable00 -type DWORD -value 0×00562401 
New-ItemProperty . ColorTable07 -type DWORD -value 0x00f0edee 
New-ItemProperty . FaceName -type STRING -value "Lucida Console" 
New-ItemProperty . FontFamily -type DWORD -value 0×00000036 
New-ItemProperty . FontSize -type DWORD -value 0x000c0000 
New-ItemProperty . FontWeight -type DWORD -value 0×00000190 
New-ItemProperty . HistoryNoDup -type DWORD -value 0×00000000 
New-ItemProperty . QuickEdit -type DWORD -value 0×00000001 
New-ItemProperty . ScreenBufferSize -type DWORD -value 0x0bb80078 
New-ItemProperty . WindowSize -type DWORD -value 0×00320078 
Pop-Location
于 2013-09-08T16:35:23.993 回答
6

此 powershell 函数模仿 cmd 行调用:color b0

function Set-ConsoleColor ($bc, $fc) {
    $Host.UI.RawUI.BackgroundColor = $bc
    $Host.UI.RawUI.ForegroundColor = $fc
    Clear-Host
}
Set-ConsoleColor 'cyan' 'black'

可以使用以下代码检索控制台颜色名​​称:

[Enum]::GetValues([ConsoleColor])
于 2015-03-01T19:30:55.067 回答
4

我已将此功能添加到我的 powershell 配置文件中,因为有一个程序经常弄乱我的 shell 的颜色。

$DefaultForeground = (Get-Host).UI.RawUI.ForegroundColor
$DefaultBackground = (Get-Host).UI.RawUI.BackgroundColor
function SetColors
{
    Param
    (
        [string]$Foreground = "",
        [string]$Background = ""
    )

    $ValidColors = "black","blue","cyan","darkblue" ,"darkcyan","darkgray",
        "darkgreen","darkmagenta","darkred","darkyellow","gray","green",
        "magenta","red","white","yellow";

    $Foreground = $Foreground.ToLower()
    $Background = $Background.ToLower()

    if ( $Foreground -eq "" )
    {
        $Foreground = $DefaultForeground
    }
    if ( $Background -eq "" )
    {
        $Background = $DefaultBackground
    }

    if ( $ValidColors -contains $Foreground -and
         $ValidColors -contains $Background )
    {
        $a = (Get-Host).UI.RawUI
        $a.ForegroundColor = $Foreground
        $a.BackgroundColor = $Background
    }
    else 
    {
        write-host "Foreground/Background Colors must be one of the following:"
        $ValidColors 
    }
}
set-alias set-colors SetColors

一些注意事项:

"$DefaultCololrs = (Get-Host).UI.RawUI"创建的指针类型对象多于对象的实际副本。这意味着,如果您稍后设置一个不同的变量等于"(Get-Host).UI.RawUI"并更改内容, $DefaultColors 也会更改(这就是为什么我确保将它们复制为字符串的原因)。

我尝试设置其他颜色(使用十六进制代码)但运气不佳,尽管我确实在配置文件脚本中找到了使用十六进制值设置 Powershell 颜色(我还没有尝试过,因为我不是特别喜欢在注册表,并且默认的颜色列表似乎足够了)。

我还找到了这个文档:https ://technet.microsoft.com/en-us/library/ff406264.aspx ,我以后可能不得不用它来弄清楚如何修改我的“grep”命令(目前我有它的别名选择字符串)

于 2016-06-22T18:48:17.033 回答