【问题标题】:Custom font color for Powershell outputPowershell 输出的自定义字体颜色
【发布时间】:2021-04-15 09:17:56
【问题描述】:

让我们使用powershell命令Write-Host "red text" -Fore red 这将在红色前景中显示“红色文本”。
但是,您希望文本以稍微浅一点的方式显示 字体颜色,浅红色。

有没有办法做到这一点并使用 powershell 在 RGB 光谱中获取任何前景色(和背景)?

【问题讨论】:

    标签: powershell colors output


    【解决方案1】:

    看到这个:https://github.com/PoshCode/Pansies
    它是执行此操作的 PowerShell 模块。 这里有一个与您的问题相关的问题: https://github.com/PowerShell/PowerShell/issues/14588
    请点击以上链接了解更多信息。

    【讨论】:

      【解决方案2】:
      
      $PSVersionTable.PSVersion
      
      Major  Minor  Patch  PreReleaseLabel BuildLabel
      -----  -----  -----  --------------- ----------
      7      1      0
      
      (0..256).ForEach{write-host "`e[38;5;$($_)m[$_]"} # background color
      (0..256).ForEach{write-host "`e[48;5;$($_)m[$_]"} # Foreground color
      
      

      【讨论】:

      • 您可能需要添加注释,说明这需要一个可以使用 ANSI 转义序列的控制台。例如,默认的 Windows 7 控制台不支持此类。 [咧嘴]
      • 不知道要不要
      • 谢谢,这成功了!有没有办法为背景做到这一点?我试图做类似write-host "`e[7;6;$(60)m[60]" 的事情,但这导致了一个非常奇怪的交替背景。
      • 您能解释一下这是如何工作的吗?特别是引号中的代码?
      猜你喜欢
      • 2019-07-26
      • 2020-06-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      相关资源
      最近更新 更多