[英]PowerShell write-host background color continuing past the code
这是一个与滚动相关的已知错误。 Write-Host
的output涉及到滚动时,背景色漏进命令行:
1..100 | % { write-host "text text text" -ForegroundColor Magenta -BackgroundColor white }
作为一种解决方法,您可以使用ANSI 转义序列进行着色,从 PS 7.2+ 开始,使用自动$PSStyle
变量非常容易:
Write-Host "$($PSStyle.Foreground.Magenta)$($PSStyle.Background.White)text text text$($PSStyle.Reset)"
$($PSStyle.Reset)
显式重置行尾的样式,这应该避免任何背景颜色泄漏到命令行中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.