Skip to content

Commit b755108

Browse files
SteveL-MSFTkilasuit
authored andcommitted
Add ConciseView for $ErrorView (PowerShell#10641)
1 parent f76ae30 commit b755108

File tree

3 files changed

+48
-53
lines changed

3 files changed

+48
-53
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -735,34 +735,15 @@ public ConsoleColorProxy(ConsoleHostUserInterface ui)
735735
_ui = ui;
736736
}
737737

738-
public ConsoleColor FormatAccentColor
739-
{
740-
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
741-
get
742-
{
743-
return _ui.FormatAccentColor;
744-
}
745-
746-
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
747-
set
748-
{
749-
_ui.FormatAccentColor = value;
750-
}
751-
}
752-
753738
public ConsoleColor ErrorAccentColor
754739
{
755740
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
756741
get
757-
{
758-
return _ui.ErrorAccentColor;
759-
}
742+
{ return _ui.ErrorAccentColor; }
760743

761744
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
762745
set
763-
{
764-
_ui.ErrorAccentColor = value;
765-
}
746+
{ _ui.ErrorAccentColor = value; }
766747
}
767748

768749
public ConsoleColor ErrorForegroundColor

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

Lines changed: 45 additions & 22 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,21 +979,37 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
979979
.AddScriptBlockExpressionBinding(@"
980980
981981
function Get-ConciseViewPositionMessage {
982-
Set-StrictMode -Off
983982
984983
$resetColor = ''
985-
if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path env:__SuppressAnsiEscapeSequences)) {
986-
$resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence(
987-
[System.Management.Automation.VTUtility+VT]::Reset
988-
)
984+
if ($Host.UI.SupportsVirtualTerminal) {
985+
$resetColor = ""`e[0m""
989986
}
990987
991-
function Get-VT100Color([ConsoleColor] $color) {
992-
if (!$Host.UI.SupportsVirtualTerminal -or (Test-Path env:__SuppressAnsiEscapeSequences)) {
988+
function Get-VT100Color([string] $color) {
989+
if (! $Host.UI.SupportsVirtualTerminal) {
993990
return ''
994991
}
995992
996-
return [System.Management.Automation.VTUtility]::GetEscapeSequence($color)
993+
$colors = @{
994+
'Black' = ""`e[2;30m""
995+
'DarkRed' = ""`e[2;31m""
996+
'DarkGreen' = ""`e[2;32m""
997+
'DarkYellow' = ""`e[2;33m""
998+
'DarkBlue' = ""`e[2;34m""
999+
'DarkMagenta' = ""`e[2;35m""
1000+
'DarkCyan' = ""`e[2;36m""
1001+
'Gray' = ""`e[2;37m""
1002+
'DarkGray' = ""`e[1;30m""
1003+
'Red' = ""`e[1;31m""
1004+
'Green' = ""`e[1;32m""
1005+
'Yellow' = ""`e[1;33m""
1006+
'Blue' = ""`e[1;34m""
1007+
'Magenta' = ""`e[1;35m""
1008+
'Cyan' = ""`e[1;36m""
1009+
'White' = ""`e[1;37m""
1010+
}
1011+
1012+
return $colors[$color]
9971013
}
9981014
9991015
# return length of string sans VT100 codes
@@ -1018,14 +1034,25 @@ function Get-ConciseViewPositionMessage {
10181034
}
10191035
10201036
return ($string.Substring(0,$length) -split '\s',-2)[0]
1037+
1038+
#if (-not $string.Contains(' ')) {
1039+
# return $string.Substring(0, $length)
1040+
#}
1041+
1042+
#$split = $string.Substring(0, $length).Split(' ')
1043+
#if ($split.Count -gt 1) {
1044+
# return [string]::Join(' ', $split, 0, $split.Count - 1)
1045+
#}
1046+
#else {
1047+
# return $split[0]
1048+
#}
10211049
}
10221050
10231051
$errorColor = ''
10241052
$accentColor = ''
1025-
1026-
if ($null -ne $Host.PrivateData) {
1027-
$errorColor = Get-VT100Color $Host.PrivateData.ErrorForegroundColor
1028-
$accentColor = Get-VT100Color ($Host.PrivateData.ErrorAccentColor ?? $errorColor)
1053+
if ($Host.PrivateData) {
1054+
$errorColor = Get-VT100Color -color $Host.PrivateData.ErrorForegroundColor
1055+
$accentColor = Get-VT100Color -color $Host.PrivateData.ErrorAccentColor
10291056
}
10301057
10311058
$posmsg = ''
@@ -1035,9 +1062,9 @@ function Get-ConciseViewPositionMessage {
10351062
$prefix = ''
10361063
$newline = [Environment]::Newline
10371064
1038-
if ($myinv -and $myinv.ScriptName -or $myinv.ScriptLineNumber -gt 1 -or $_.CategoryInfo.Category -eq 'ParserError') {
1065+
if ($myinv -and $myinv.ScriptName -or $_.CategoryInfo.Category -eq 'ParserError') {
10391066
if ($myinv.ScriptName) {
1040-
$posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}""
1067+
$posmsg = ""error in${resetcolor} $($myinv.ScriptName)${newline}""
10411068
}
10421069
else {
10431070
$posmsg = ""${newline}""
@@ -1058,12 +1085,8 @@ function Get-ConciseViewPositionMessage {
10581085
$line = $myinv.Line
10591086
$highlightLine = $myinv.PositionMessage.Split('+').Count - 1
10601087
$offsetLength = $myinv.PositionMessage.split('+')[$highlightLine].Trim().Length
1061-
1062-
# don't color the whole line red
1063-
if ($offsetLength -lt $line.Length - 1) {
1064-
$line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor).Insert($myinv.OffsetInLine - 1, $accentColor)
1065-
}
1066-
1088+
$line = $line.Insert($myinv.OffsetInLine - 1 + $offsetLength, $resetColor)
1089+
$line = $line.Insert($myinv.OffsetInLine - 1, $errorColor)
10671090
$posmsg += ""${accentColor}${lineWhitespace}$($myinv.ScriptLineNumber) ${verticalBar} ${resetcolor}${line}`n""
10681091
$offsetWhitespace = ' ' * ($myinv.OffsetInLine - 1)
10691092
$prefix = ""${accentColor}${headerWhitespace} ${verticalBar} ${errorColor}""
@@ -1126,7 +1149,7 @@ function Get-ConciseViewPositionMessage {
11261149
elseif ($_.CategoryInfo.Category) {
11271150
$reason = $_.CategoryInfo.Category
11281151
}
1129-
elseif ($_.CategoryInfo.Reason) {
1152+
elseif ($_CategoryInfo.Reason) {
11301153
$reason = $_.CategoryInfo.Reason
11311154
}
11321155

src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,7 @@ static ExperimentalFeature()
117117
description: "Support the ternary operator in PowerShell language"),
118118
new ExperimentalFeature(
119119
name: "PSErrorView",
120-
description: "New formatting for ErrorRecord"),
121-
new ExperimentalFeature(
122-
name: "PSUpdatesNotification",
123-
description: "Print notification message when new releases are available"),
124-
new ExperimentalFeature(
125-
name: "PSCoalescingOperators",
126-
description: "Support the null coalescing operator and null coalescing assignment operator in PowerShell language"),
127-
new ExperimentalFeature(
128-
name: "PSPipelineChainOperators",
129-
description: "Allow use of && and || as operators between pipeline invocations"),
120+
description: "New formatting for ErrorRecord")
130121
};
131122
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
132123

0 commit comments

Comments
 (0)