@@ -926,7 +926,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
926
926
CustomControl . Create ( outOfBand : true )
927
927
. StartEntry ( )
928
928
. AddScriptBlockExpressionBinding ( @"
929
- if (@('NativeCommandErrorMessage', 'NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
929
+ if (@('NativeCommandErrorMessage'. 'NativeCommandError') -notcontains $_.FullyQualifiedErrorId -and @('CategoryView','ConciseView') -notcontains $ErrorView)
930
930
{
931
931
$myinv = $_.InvocationInfo
932
932
if ($myinv -and $myinv.MyCommand)
@@ -979,21 +979,37 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_System_Management_Autom
979
979
. AddScriptBlockExpressionBinding ( @"
980
980
981
981
function Get-ConciseViewPositionMessage {
982
- Set-StrictMode -Off
983
982
984
983
$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""
989
986
}
990
987
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) {
993
990
return ''
994
991
}
995
992
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]
997
1013
}
998
1014
999
1015
# return length of string sans VT100 codes
@@ -1018,14 +1034,25 @@ function Get-ConciseViewPositionMessage {
1018
1034
}
1019
1035
1020
1036
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
+ #}
1021
1049
}
1022
1050
1023
1051
$errorColor = ''
1024
1052
$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
1029
1056
}
1030
1057
1031
1058
$posmsg = ''
@@ -1035,9 +1062,9 @@ function Get-ConciseViewPositionMessage {
1035
1062
$prefix = ''
1036
1063
$newline = [Environment]::Newline
1037
1064
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') {
1039
1066
if ($myinv.ScriptName) {
1040
- $posmsg = ""${resetcolor}$($myinv.ScriptName)${newline}""
1067
+ $posmsg = ""error in ${resetcolor} $($myinv.ScriptName)${newline}""
1041
1068
}
1042
1069
else {
1043
1070
$posmsg = ""${newline}""
@@ -1058,12 +1085,8 @@ function Get-ConciseViewPositionMessage {
1058
1085
$line = $myinv.Line
1059
1086
$highlightLine = $myinv.PositionMessage.Split('+').Count - 1
1060
1087
$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)
1067
1090
$posmsg += ""${accentColor}${lineWhitespace}$($myinv.ScriptLineNumber) ${verticalBar} ${resetcolor}${line}`n""
1068
1091
$offsetWhitespace = ' ' * ($myinv.OffsetInLine - 1)
1069
1092
$prefix = ""${accentColor}${headerWhitespace} ${verticalBar} ${errorColor}""
@@ -1126,7 +1149,7 @@ function Get-ConciseViewPositionMessage {
1126
1149
elseif ($_.CategoryInfo.Category) {
1127
1150
$reason = $_.CategoryInfo.Category
1128
1151
}
1129
- elseif ($_.CategoryInfo .Reason) {
1152
+ elseif ($_CategoryInfo .Reason) {
1130
1153
$reason = $_.CategoryInfo.Reason
1131
1154
}
1132
1155
0 commit comments