Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,13 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Microsoft_PowerShell_Co
.AddItemScriptBlock(@"
$result = $_.Content
$result = $result.Substring(0, [Math]::Min($result.Length, 200) )
if($result.Length -eq 200) { $result += ""..."" }
if($result.Length -eq 200) { $result += ""`u{2026}"" }
$result
", label: "Content")
.AddItemScriptBlock(@"
$result = $_.RawContent
$result = $result.Substring(0, [Math]::Min($result.Length, 200) )
if($result.Length -eq 200) { $result += ""..."" }
if($result.Length -eq 200) { $result += ""`u{2026}"" }
$result
", label: "RawContent")
.AddItemProperty(@"Headers")
Expand All @@ -1328,7 +1328,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Microsoft_PowerShell_Co
.AddItemScriptBlock(@"
$result = $_.RawContent
$result = $result.Substring(0, [Math]::Min($result.Length, 200) )
if($result.Length -eq 200) { $result += ""..."" }
if($result.Length -eq 200) { $result += ""`u{2026}"" }
$result
", label: "RawContent")
.AddItemProperty(@"Headers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static IEnumerable<FormatViewDefinition> ViewsOf_Microsoft_PowerShell_Co
Select * -Exclude PSPath,PSParentPath,PSChildName,PSDrive,PsProvider |
Format-List | Out-String | Sort).Trim()
$result = $result.Substring(0, [Math]::Min($result.Length, 5000) )
if($result.Length -eq 5000) { $result += ""..."" }
if($result.Length -eq 5000) { $result += ""`u{2026}"" }
$result
")
.EndRowDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ internal static string TruncateAtNewLine(string s)
return s;
}

return s.Substring(0, lineBreak) + PSObjectHelper.ellipses;
return s.Substring(0, lineBreak) + PSObjectHelper.Ellipsis;
}

internal static string PadLeft(string val, int count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private void DisplayEnumerationInner(IEnumerable e, TraversalInfo level, List<Fo
{
if (_enumerationLimit == enumCount)
{
DisplayLeaf(PSObjectHelper.ellipses, formatValueList);
DisplayLeaf(PSObjectHelper.Ellipsis, formatValueList);
break;
}
enumCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Specialized;
using System.Management.Automation.Internal;
using System.Text;
using Microsoft.PowerShell.Commands.Internal.Format;

namespace Microsoft.PowerShell.Commands.Internal.Format
{
Expand Down Expand Up @@ -37,6 +38,8 @@ private class ScreenInfo
}

private ScreenInfo _si;
private const char ESC = '\u001b';
private const string ResetConsoleVt100Code = "\u001b[m";

internal static int ComputeWideViewBestItemsPerRowFit(int stringLen, int screenColumns)
{
Expand Down Expand Up @@ -413,7 +416,13 @@ private string GenerateRow(string[] values, ReadOnlySpan<int> alignment, Display
sb.Append(StringUtil.Padding(_startColumn));
}
}

sb.Append(GenerateRowField(values[k], _si.columnInfo[k].width, alignment[k], dc, addPadding));
if (values[k].IndexOf(ESC) != -1)
{
// Reset the console output if the content of this column contains ESC
sb.Append(ResetConsoleVt100Code);
}
}
return sb.ToString();
}
Expand Down Expand Up @@ -468,7 +477,7 @@ private static string GenerateRowField(string val, int width, int alignment, Dis
{
// the string is longer than the width of the column
// truncate and add ellipsis if it's too long
int truncationDisplayLength = width - ellipsis.Length;
int truncationDisplayLength = width - EllipsisSize;

if (truncationDisplayLength > 0)
{
Expand All @@ -480,15 +489,15 @@ private static string GenerateRowField(string val, int width, int alignment, Dis
// get from "abcdef" to "...f"
int tailCount = dc.GetTailSplitLength(s, truncationDisplayLength);
s = s.Substring(s.Length - tailCount);
s = ellipsis + s;
s = PSObjectHelper.Ellipsis + s;
}
break;

case TextAlignment.Center:
{
// get from "abcdef" to "a..."
s = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
s += ellipsis;
s += PSObjectHelper.Ellipsis;
}
break;

Expand All @@ -497,7 +506,7 @@ private static string GenerateRowField(string val, int width, int alignment, Dis
// left align is the default
// get from "abcdef" to "a..."
s = s.Substring(0, dc.GetHeadSplitLength(s, truncationDisplayLength));
s += ellipsis;
s += PSObjectHelper.Ellipsis;
}
break;
}
Expand Down Expand Up @@ -574,7 +583,7 @@ private static string GenerateRowField(string val, int width, int alignment, Dis
return s;
}

private const string ellipsis = "...";
private const int EllipsisSize = 1;

private bool _disabled = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary>
internal static class PSObjectHelper
{
internal const string ellipses = "...";
internal const char Ellipsis = '\u2026';

internal static string PSObjectIsOfExactType(Collection<string> typeNames)
{
Expand Down Expand Up @@ -308,7 +308,7 @@ internal static string SmartToString(PSObject so, PSPropertyExpressionFactory ex
{
if (enumCount == enumerationLimit)
{
sb.Append(ellipses);
sb.Append(Ellipsis);
break;
}
enumCount++;
Expand All @@ -335,7 +335,7 @@ internal static string SmartToString(PSObject so, PSPropertyExpressionFactory ex
{
if (enumCount == enumerationLimit)
{
sb.Append(ellipses);
sb.Append(Ellipsis);
break;
}
enumCount++;
Expand Down
10 changes: 7 additions & 3 deletions src/System.Management.Automation/engine/ErrorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public override string ToString()
/// control the maximum length of the GetMessage() string, we
/// ellipsize these strings. The current heuristic is to take
/// strings longer than 40 characters and ellipsize them to
/// the first and last 15 characters plus "..." in the middle.
/// the first and last 19 characters plus "..." in the middle.
/// </summary>
/// <param name="uiCultureInfo">culture to retrieve template if needed</param>
/// <param name="original">original string</param>
Expand All @@ -476,8 +476,12 @@ internal static string Ellipsize(CultureInfo uiCultureInfo, string original)
{
return original;
}
string first = original.Substring(0, 15);
string last = original.Substring(original.Length - 15, 15);

// We are splitting a string > 40 chars in half, so left and right can be
// at most 19 characters to include the ellipsis in the middle.
const int MaxHalfWidth = 19;
string first = original.Substring(0, MaxHalfWidth);
string last = original.Substring(original.Length - MaxHalfWidth, MaxHalfWidth);
return
string.Format(uiCultureInfo, ErrorPackage.Ellipsize, first, last);
}
Expand Down
3 changes: 2 additions & 1 deletion src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Diagnostics.CodeAnalysis;
using Microsoft.PowerShell.Commands.Internal.Format;

namespace System.Management.Automation
{
Expand Down Expand Up @@ -3984,7 +3985,7 @@ internal void TraceVariableSet(string varName, object value)

if (valAsString.Length > msgLength)
{
valAsString = valAsString.Substring(0, msgLength) + "...";
valAsString = valAsString.Substring(0, msgLength) + PSObjectHelper.Ellipsis;
}
Trace("TraceVariableAssignment", ParserStrings.TraceVariableAssignment, varName, valAsString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.PowerShell.Commands;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Internal;
Expand All @@ -15,6 +14,8 @@
using System.Runtime.InteropServices;
using System.Security;
using System.Globalization;
using Microsoft.PowerShell.Commands;
using Microsoft.PowerShell.Commands.Internal.Format;

namespace System.Management.Automation
{
Expand Down Expand Up @@ -250,7 +251,7 @@ internal static string GetMaxLines(string source, int maxLines)

if (lineCount == maxLines)
{
returnValue.Append("...");
returnValue.Append(PSObjectHelper.Ellipsis);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Management.Automation.Runspaces;
using Dbg = System.Management.Automation.Diagnostics;
using System.Collections;
using Microsoft.PowerShell.Commands.Internal.Format;

namespace Microsoft.PowerShell.Commands
{
Expand Down Expand Up @@ -1151,7 +1152,7 @@ private void SetRunspacePrompt(RemoteRunspace remoteRunspace)

case ContainerIdParameterSet:
targetName = (this.ContainerId.Length <= 15) ? this.ContainerId
: this.ContainerId.Remove(12) + "...";
: this.ContainerId.Remove(14) + PSObjectHelper.Ellipsis;
break;

case SessionParameterSet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Microsoft.PowerShell.Commands;
using Microsoft.PowerShell.Commands.Internal.Format;

// ReSharper disable UnusedMember.Global

Expand Down Expand Up @@ -1234,7 +1235,7 @@ internal static void DefineFunction(ExecutionContext context,
var expAttribute = scriptBlock.ExperimentalAttribute;
if (expAttribute == null || expAttribute.ToShow)
{
context.EngineSessionState.SetFunctionRaw(functionDefinitionAst.Name,
context.EngineSessionState.SetFunctionRaw(functionDefinitionAst.Name,
scriptBlock, context.EngineSessionState.CurrentScope.ScopeOrigin);
}
}
Expand Down Expand Up @@ -1294,7 +1295,7 @@ internal static void AddKeyValuePair(IDictionary hashtable, object key, object v

if (errorKeyString.Length > 40)
{
errorKeyString = errorKeyString.Substring(0, 40) + "...";
errorKeyString = errorKeyString.Substring(0, 40) + PSObjectHelper.Ellipsis;
}

throw InterpreterError.NewInterpreterException(hashtable, typeof(RuntimeException), errorExtent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Ellipsize" xml:space="preserve">
<value>{0}...{1}</value>
<value>{0}\u2026{1}</value>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this should have been &#x2026; rather than \u2026; see #9586.

</data>
<data name="ErrorDetailsEmptyTemplate" xml:space="preserve">
<value>Error text is empty for error "{0}" : "{1}"</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Describe "Format-List DRT basic functionality" -Tags "CI" {
$info = @{}
$info.array = $al
$result = $info | Format-List | Out-String
$result | Should -Match "Name : array\s+Value : {0, 1, 2, 3...}"
$result | Should -Match "Name : array\s+Value : {0, 1, 2, 3`u{2026}}" # ellipsis
}

It "Format-List with No Objects for End-To-End should work"{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Describe "Format-Table" -Tags "CI" {
$info = @{}
$info.array = $al
$result = $info | Format-Table | Out-String
$result | Should -Match "array\s+{0, 1, 2, 3...}"
$result | Should -Match "array\s+{0, 1, 2, 3`u{2026}}" # ellipsis
}

It "Format-Table with Negative Count should work" {
Expand Down Expand Up @@ -255,8 +255,9 @@ Left Center Right

It "Format-Table should not have trailing whitespace if there is truncation: <view>" -TestCases @(
# `u{2B758} is a double-byte Japanese character
@{view="Test.Format.Left" ; object=[pscustomobject]@{Left="123`u{2B758}"} ; expected="Left----1..." },
@{view="Test.Format.Center"; object=[pscustomobject]@{Center="12345`u{2B758}"}; expected="Center------123..."}
# `u{2026} is the ellipsis
@{view="Test.Format.Left" ; object=[pscustomobject]@{Left="123`u{2B758}"} ; expected="Left----123`u{2026}" },
@{view="Test.Format.Center"; object=[pscustomobject]@{Center="12345`u{2B758}"}; expected="Center------12345`u{2026}"}
) {
param($view, $object, $expected)

Expand Down Expand Up @@ -501,7 +502,7 @@ Long*********r3
Head
er
----*-------*-----
1...*...5678*12...
123`u{2026}*`u{2026}345678*1234`u{2026}


"@ },
Expand All @@ -513,7 +514,7 @@ ngH
ead
er
---
123
12`u{2026}


"@ },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Describe "Out-File" -Tags "CI" {
$actual[0] | Should -BeNullOrEmpty
$actual[1] | Should -BeExactly "text"
$actual[2] | Should -BeExactly "----"
$actual[3] | Should -BeExactly "some te..."
$actual[3] | Should -BeExactly "some test`u{2026}" # ellipsis
}

It "Should allow the cmdlet to overwrite an existing read-only file" {
Expand Down