行错误
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
信息
目前此功能仅适用于 powershell。
行错误功能启用后,当输入无效文本时会替换提示符的最后部分。它利用
PSReadLine 的 -PromptText 设置,通过添加两个不同的提示符来实现:
一个用于有效行,另一个用于错误行。由于 PSReadLine 会根据当前行的状态,
用对应值重写提示符的最后部分,因此你需要确保所有设置兼容,
因为这些值仅在 shell 启动时设置一次。
有两个配置项需要调整:
-
valid_line: 当行有效时显示 -
error_line: 当行出现错误时显示
你可以使用 go 的 text/template 模板,并通过 sprig 扩展来增强文本功能。
配置
你需要扩展或创建自定义主题并覆盖提示符设置。例如:
- json
- yaml
- toml
{
"valid_line": {
"background": "transparent",
"foreground": "#ffffff",
"template": "<#e0def4,#286983> </><#286983,transparent></> "
},
"error_line": {
"background": "transparent",
"foreground": "#ffffff",
"template": "<#eb6f92,#286983> </><#286983,transparent></> "
}
}
valid_line:
background: transparent
foreground: "#ffffff"
template: "<#e0def4,#286983> </><#286983,transparent></> "
error_line:
background: transparent
foreground: "#ffffff"
template: "<#eb6f92,#286983> </><#286983,transparent></> "
[valid_line]
background = "transparent"
foreground = "#ffffff"
template = "<#e0def4,#286983> </><#286983,transparent></> "
[error_line]
background = "transparent"
foreground = "#ffffff"
template = "<#eb6f92,#286983> </><#286983,transparent></> "
选项
| Name | Type | Description |
|---|---|---|
background | string | color |
foreground | string | color |
template | string | a fully featured template - defaults to empty |