powershell - Powershell在启动时不运行颜色更改
问题描述
我一直在工作,但我刚刚更新了 windows,现在我的 powershell 配置文件没有正确更新颜色。
以前工作的配置文件代码:
Set-PSReadLineOption -Colors @{
"ContinuationPrompt" = [ConsoleColor]:: DarkGray
"Emphasis" = [ConsoleColor]:: DarkGray
"Error" = [ConsoleColor]:: DarkGray
"Selection" = [ConsoleColor]:: DarkGray
"Default" = [ConsoleColor]:: DarkGray
"Comment" = [ConsoleColor]:: DarkGray
"Keyword" = [ConsoleColor]:: DarkGray
"String" = [ConsoleColor]:: DarkGray
"Operator" = [ConsoleColor]:: DarkGray
"Variable" = [ConsoleColor]:: DarkGray
"Command" = [ConsoleColor]:: DarkGray
"Parameter" = [ConsoleColor]:: DarkGray
"Type" = [ConsoleColor]:: DarkGray
"Number" = [ConsoleColor]:: DarkGray
"Member" = [ConsoleColor]:: DarkGray
}
当我将 echo 添加到顶部时,它会在打开 powershell 时正确打印,但颜色不会改变。
echo "hello"
Set-PSReadLineOption -Colors @{
"ContinuationPrompt" = [ConsoleColor]:: DarkGray
"Emphasis" = [ConsoleColor]:: DarkGray
"Error" = [ConsoleColor]:: DarkGray
"Selection" = [ConsoleColor]:: DarkGray
"Default" = [ConsoleColor]:: DarkGray
"Comment" = [ConsoleColor]:: DarkGray
"Keyword" = [ConsoleColor]:: DarkGray
"String" = [ConsoleColor]:: DarkGray
"Operator" = [ConsoleColor]:: DarkGray
"Variable" = [ConsoleColor]:: DarkGray
"Command" = [ConsoleColor]:: DarkGray
"Parameter" = [ConsoleColor]:: DarkGray
"Type" = [ConsoleColor]:: DarkGray
"Number" = [ConsoleColor]:: DarkGray
"Member" = [ConsoleColor]:: DarkGray
}
解决方案
实际上,它对我有用,你可以只说“深灰色”作为颜色。唯一需要注意的是,您不能在 powershell 5 中使用“`e”。请注意,Windows 终端在其方案中重新定义了颜色,就像任何控制台程序一样。
在转义序列方面,DarkGray 变为“亮黑色”或“esc[90m” https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_ 控制台颜色和 ansi 颜色有一些不同的形容词。
psreadline中的一些常用代码。其中一些在 windows 终端的日晒方案中变得不可见,因为亮白色或亮黑色被设置为与背景相同的颜色。
Command "$([char]0x1b)[31m" red # 93 bright yellow
Comment "$([char]0x1b)[32m" green
ContinuationPrompt "$([char]0x1b)[37m" white # 33 yellow
DefaultToken "$([char]0x1b)[37m" white
Emphasis "$([char]0x1b)[96m" bright cyan
Error "$([char]0x1b)[91m" bright red
Keyword "$([char]0x1b)[92m" bright green
Member "$([char]0x1b)[97m" bright white
Number "$([char]0x1b)[97m" bright white
Operator "$([char]0x1b)[90m" bright black
Parameter "$([char]0x1b)[90m" bright black
Selection "$([char]0x1b)[30;47m" black on white # 35;43 magenta;yellow
String "$([char]0x1b)[36m" cyan
Type "$([char]0x1b)[37m" white
Variable "$([char]0x1b)[92m" bright green
推荐阅读
- ssl - Hyperledger Fabric - 调用错误/TLS 握手失败并出现错误 tls:第一条记录看起来不像 TLS 握手
- java - java程序没有完成for循环为什么?
- python - 是否可以在 Python 列表理解中编写多个语句?
- emacs - Centos 7.6 emacsclient 找不到套接字
- python - AWS:在 DeepLens 设备上运行 Rekognition
- java - 通过 Java 中的反射设置私有字段的最短、最好、最干净的方法是什么?
- c# - .NET Framework 安装后需要 WIX Bootstrapper 重新启动并跳过应用程序启动
- sql-server - SQL 触发器 - 插入后,更新错误和正确的值
- powerbi - 通过 SQL 在 powerBI 中显示表情符号
- c++ - 如何转发元组的类型以专门化其他模板?