简体   繁体   English

powershell中的一个output如何加粗?

[英]How does one output bold text in powershell?

I got a Powershell script that do some automatic procedures, I use a "Write-Host" at the end of each one of them to tell the technical user that step is finished, but I realize is kind of hard to read and keep track so, ¿Is there a way to output a bold text?我有一个Powershell脚本,它执行一些自动程序,我在每个程序的末尾使用“Write-Host”来告诉技术用户该步骤已完成,但我意识到有点难以阅读和跟踪所以, ¿ 有没有办法将 output 变成粗体字?

Thank you in advance.先感谢您。

Just wording...只是措辞...
Seen from the 'ConvertFrom-MarkDown` cmdlet (included with PowerShell 6 and higher), bold text actually exists:'ConvertFrom-MarkDown` cmdlet(包含在PowerShell 6 及更高版本中) 来看,实际存在粗体文本:
(Using the default PowerShell color scheme) (使用默认的 PowerShell 配色方案)

('This is **Bold** text' | ConvertFrom-MarkDown -AsVt100EncodedString).VT100EncodedString

在此处输入图片说明

But this is not completely fair, as behind the scenes, it is a matter of playing with colors.但这并不完全公平,因为在幕后,这是玩颜色的问题。 Knowing that the default foregroundcolor is Gray and White is just a little brigther and therefore looks Bold .知道默认的前景色是GrayWhite只是稍微亮一点,因此看起来很大胆
Meaning that the above statement is similar to:意思是上面的语句类似于:

Write-Host 'This is ' -NoNewline; Write-Host -ForegroundColor White 'Bold ' -NoNewline; Write-Host 'Text'

As far as I know it is not possible, but you can change the foregroundcolor and backgroundcolor of the text.据我所知这是不可能的,但您可以更改文本的前景色背景色 This way you can output text in different colors, so you can highlight an error or a warning.通过这种方式,您可以输出不同颜色的文本,以便突出显示错误或警告。


This displays a red text:这将显示红色文本:

Write-Host "This text is red" -ForegroundColor red

This displays a blue text on a red background:这会在红色背景上显示蓝色文本:

Write-Host "This text is blue" -ForegroundColor blue -BackgroundColor red

More here: https://evotec.xyz/powershell-how-to-format-powershell-write-host-with-multiple-colors/更多信息: https : //evotec.xyz/powershell-how-to-format-powershell-write-host-with-multiple-colors/

See also:也可以看看:

Console Virtual Terminal Sequences 控制台虚拟终端序列

Starting in PowerShell 5.1, the PowerShell console supports VT escape sequences that can be used to position and format console text.从 PowerShell 5.1 开始,PowerShell 控制台支持可用于定位和格式化控制台文本的 VT 转义序列。 Note that this请注意,这

# Enable underline
$esc = [char]27
"$esc[4mOutput is now underlined!"

# Disable underline
$esc = [char]27
"$esc[0mReset"

Or as pointed out already, with Write-Host, just switch the text color inline for contrast...或者正如已经指出的那样,使用 Write-Host,只需切换内联文本颜色以进行对比度......

Write-Host -ForegroundColor gray 'This is not bold ' -NoNewline
Write-Host -ForegroundColor White 'This is Bold ' -NoNewline
Write-Host -ForegroundColor gray 'This is not bold'

... that is if you did not download or can't download and use external stuff. ...也就是说,如果您没有下载或无法下载和使用外部内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM