Skip to content

Commit 13fe488

Browse files
SteveL-MSFTkilasuit
authored andcommitted
Update ConciseView to remove unnecessary text and not color entire line in red (PowerShell#10724)
1 parent bc8f2f8 commit 13fe488

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
926926
CustomControl.Create(outOfBand: true)
927927
.StartEntry()
928928
.AddScriptBlockExpressionBinding(@"
929-
if (@('NativeCommandErrorMessage'.'NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
929+
if (@('NativeCommandErrorMessage','NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
930930
{
931931
$myinv = $_.InvocationInfo
932932
if ($myinv -and $myinv.MyCommand)
@@ -979,6 +979,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
979979
.AddScriptBlockExpressionBinding(@"
980980
981981
function Get-ConciseViewPositionMessage {
982+
Set-StrictMode -Off
982983
983984
$resetColor = ''
984985
if ($Host.UI.SupportsVirtualTerminal) {
@@ -1064,7 +1065,7 @@ function Get-ConciseViewPositionMessage {
10641065
10651066
if ($myinv -and $myinv.ScriptName -or $_.CategoryInfo.Category -eq 'ParserError') {
10661067
if ($myinv.ScriptName) {
1067-
$posmsg = ""error in${resetcolor} $($myinv.ScriptName)${newline}""
1068+
$posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}""
10681069
}
10691070
else {
10701071
$posmsg = ""${newline}""
@@ -1085,8 +1086,12 @@ function Get-ConciseViewPositionMessage {
10851086
$line = $myinv.Line
10861087
$highlightLine = $myinv.PositionMessage.Split('+').Count - 1
10871088
$offsetLength = $myinv.PositionMessage.split('+')[$highlightLine].Trim().Length
1088-
$line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor)
1089-
$line = $line.Insert($myinv.OffsetInLine - 1, $errorColor)
1089+
1090+
# don't color the whole line red
1091+
if ($offsetLength -lt $line.Length - 1) {
1092+
$line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor).Insert($myinv.OffsetInLine - 1, $accentColor)
1093+
}
1094+
10901095
$posmsg += ""${accentColor}${lineWhitespace}$($myinv.ScriptLineNumber) ${verticalBar} ${resetcolor}${line}`n""
10911096
$offsetWhitespace = ' ' * ($myinv.OffsetInLine - 1)
10921097
$prefix = ""${accentColor}${headerWhitespace} ${verticalBar} ${errorColor}""
@@ -1149,7 +1154,7 @@ function Get-ConciseViewPositionMessage {
11491154
elseif ($_.CategoryInfo.Category) {
11501155
$reason = $_.CategoryInfo.Category
11511156
}
1152-
elseif ($_CategoryInfo.Reason) {
1157+
elseif ($_.CategoryInfo.Reason) {
11531158
$reason = $_.CategoryInfo.Reason
11541159
}
11551160

0 commit comments

Comments
 (0)