Skip to content
Closed
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
19 changes: 15 additions & 4 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,13 @@ internal static int LengthInBufferCells(string str, int offset, bool checkEscape
}
}

return str.Length - offset - escapeSequenceAdjustment;
var totalWidthInCells = 0;
for (int i = offset; i < str.Length; i++)
{
totalWidthInCells += LengthInBufferCells(str[i]);
}

return totalWidthInCells - escapeSequenceAdjustment;
}

#if !UNIX
Expand All @@ -2785,9 +2791,10 @@ internal static bool IsCJKOutputCodePage(out uint codePage)
{
codePage = NativeMethods.GetConsoleOutputCP();
return codePage == 932 || // Japanese
codePage == 936 || // Simplified Chinese
codePage == 949 || // Korean
codePage == 950; // Traditional Chinese
codePage == 936 || // Simplified Chinese
codePage == 949 || // Korean
codePage == 950 || // Traditional Chinese
codePage == 65001; // UTF-8
}

#endif
Expand Down Expand Up @@ -2950,6 +2957,8 @@ private static HostException CreateHostException(

#endregion helper

#endif

#region

internal static int LengthInBufferCells(char c)
Expand Down Expand Up @@ -2977,6 +2986,8 @@ internal static int LengthInBufferCells(char c)

#endregion

#if !UNIX

#region SendInput

internal static void MimicKeyPress(INPUT[] inputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,18 @@ Left Center Right
$output = $ps.Invoke()
$output.Replace("`n","").Replace("`r","") | Should BeExactly $expected
}

It "Format-Table should pad correct spaces for CJK characters" {
$obj1 = @{'軟' = "han"}
$obj2 = @{'ソフト' = "kana"}
$obj3 = @{'soft' = "ascii"}
$objs = New-Object System.Collections.ArrayList
$objs.Add($obj1)
$objs.Add($obj2)
$objs.Add($obj3)
$result = $objs | Format-Table -AutoSize -HideTableHeaders | Out-String
$result | Should -Match "軟 han"
$result | Should -Match "ソフト kana"
$result | Should -Match "soft ascii"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,16 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" {
$result | Should Match " GroupingKey:"
$result | Should Match "name2\s+name3"
}

It "Format-Wide should pad correct spaces for CJK characters" {
$obj1 = @{'軟' = "han"}
$obj2 = @{'ソフト' = "kana"}
$obj3 = @{'soft' = "ascii"}
$objs = New-Object System.Collections.ArrayList
$objs.Add($obj1)
$objs.Add($obj2)
$objs.Add($obj3)
$result = $objs | Format-Wide -AutoSize | Out-String
$result | Should -BeExactly "軟 ソフト soft"
}
}