Skip to content

Commit 5d0fde3

Browse files
committed
Fix integrated console input and output of Unicode characters
This change resolves PowerShell/vscode-powershell#543 which reports that characters typed using AltGr combinations cannot be typed into the integrated console. It also resolves the console's inability to write Unicode characters as output by setting the console's OutputEncoding correctly.
1 parent 7e6acf9 commit 5d0fde3

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/PowerShellEditorServices/Console/ConsoleReadLine.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ public async Task<SecureString> ReadSecureLine(CancellationToken cancellationTok
6767
// Break to return the completed string
6868
break;
6969
}
70-
if ((keyInfo.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt)
71-
{
72-
continue;
73-
}
74-
if ((keyInfo.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control)
75-
{
76-
continue;
77-
}
7870
if (keyInfo.Key == ConsoleKey.Tab)
7971
{
8072
continue;
@@ -178,13 +170,7 @@ private async Task<string> ReadLine(bool isCommandLine, CancellationToken cancel
178170
consoleWidth,
179171
currentCursorIndex);
180172

181-
if ((keyInfo.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt ||
182-
(keyInfo.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control)
183-
{
184-
// Ignore any Ctrl or Alt key combinations
185-
continue;
186-
}
187-
else if (keyInfo.Key == ConsoleKey.Tab && isCommandLine)
173+
if (keyInfo.Key == ConsoleKey.Tab && isCommandLine)
188174
{
189175
if (currentCompletion == null)
190176
{

src/PowerShellEditorServices/Session/SessionPSHostUserInterface.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ internal IConsoleHost ConsoleHost
5151
/// </summary>
5252
public ConsoleServicePSHostUserInterface(bool enableConsoleRepl)
5353
{
54+
if (enableConsoleRepl)
55+
{
56+
// Set the output encoding to Unicode so that all
57+
// Unicode characters are written correctly
58+
System.Console.OutputEncoding = System.Text.Encoding.Unicode;
59+
}
60+
5461
this.rawUserInterface =
5562
enableConsoleRepl
5663
? (PSHostRawUserInterface)new ConsoleServicePSHostRawUserInterface()

0 commit comments

Comments
 (0)