首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何关闭控制台中的语法高亮显示?

如何关闭控制台中的语法高亮显示?
EN

Stack Overflow用户
提问于 2016-02-06 21:31:23
回答 6查看 10.7K关注 0票数 16

我只想让PowerShell成为白色背景上的黑色文本。然而,PowerShell v5突出显示了我的命令,并使它们变黄,这是不可能看到的。有办法关闭PowerShell中的所有语法高亮显示吗?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2016-02-07 01:07:01

PowerShell v5中的语法着色可以通过Set-PSReadlineOption进行修改。以下命令将注释的前色和背景色设置为shell前景和背景色:

代码语言:javascript
运行
复制
Set-PSReadlineOption -TokenKind Comment -ForegroundColor $Host.UI.RawUI.ForegroundColor -BackgroundColor $Host.UI.RawUI.BackgroundColor

或者只是黑白相间:

代码语言:javascript
运行
复制
Set-PSReadlineOption -TokenKind Comment -ForegroundColor Black -BackgroundColor White

您需要对所有TokenKind值执行此操作,以完全删除语法着色。

如果还想改变输出流的颜色,可以通过主机的PrivateData对象的属性来做到这一点:

代码语言:javascript
运行
复制
$Host.PrivateData.WarningForegroundColor = $Host.UI.RawUI.ForegroundColor
$Host.PrivateData.WarningBackgroundColor = $Host.UI.RawUI.BackgroundColor
...

将所有这些语句放入您的配置文件中,以便在每次启动PowerShell时应用这些语句,例如:

代码语言:javascript
运行
复制
$HOME\Documents\WindowsPowerShell\profile.ps1
票数 9
EN

Stack Overflow用户

发布于 2019-11-27 07:40:39

在最近的更新中,语法发生了变化。旧的语法现在将给您一个讨厌的错误消息:

代码语言:javascript
运行
复制
Set-PSReadLineOption : A positional parameter cannot be found that accepts argument 'Command'.                                                             
At line:1 char:1                                                                
+ Set-PSReadLineOption 'Command' white black                                    
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                    
    + CategoryInfo          : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption                      

代码语言:javascript
运行
复制
Set-PSReadLineOption : A parameter cannot be found that matches parameter name  'TokenKind'.
At line:1 char:22
+ Set-PSReadlineOption -TokenKind Comment -ForegroundColor 'black' -Bac ...
+                      ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-PSReadLineOption], Par ameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetP SReadLineOption

更新的语法似乎要求您传递一个新设置的字典。

代码语言:javascript
运行
复制
Set-PSReadLineOption -Colors @{None='black';Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}

如果你

代码语言:javascript
运行
复制
Set-PSReadLineOption: 'None' is not a valid color property

(这显然意味着您在Linux上),取出None='black';,如下所示:

代码语言:javascript
运行
复制
Set-PSReadLineOption -Colors @{Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}    

另见https://github.com/PowerShell/PSReadLine/issues/738

票数 6
EN

Stack Overflow用户

发布于 2021-04-05 14:58:36

https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.1#example-4--set-multiple-color-options

代码语言:javascript
运行
复制
Set-PSReadLineOption -Colors @{
  Command            = 'White'
  Number             = 'White'
  Member             = 'White'
  Operator           = 'White'
  Type               = 'White'
  Variable           = 'White'
  Parameter          = 'White'
  ContinuationPrompt = 'White'
  Default            = 'White'
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35246709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档