Skip to content

Commit

Permalink
add check if stdin is using console before font check
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Lee (POWERSHELL) committed Oct 4, 2018
1 parent 015abde commit 2f4e5fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions PSReadLine/PlatformWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ private static bool SetConsoleOutputVirtualTerminalProcessing()
&& SetConsoleMode(handle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}

internal static bool IsConsoleInput()
{
var handle = GetStdHandle((uint)StandardHandleId.Input);
return GetFileType(handle) == FILE_TYPE_CHAR;
}

private static bool IsHandleRedirected(bool stdin)
{
var handle = GetStdHandle((uint)(stdin ? StandardHandleId.Input : StandardHandleId.Output));
Expand Down
2 changes: 1 addition & 1 deletion PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private void Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)

// Don't change the OutputEncoding if already UTF8 or using raster font on Windows
_changeOutputEncoding = _initialOutputEncoding != Encoding.UTF8;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformWindows.IsUsingRasterFont())
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && PlatformWindows.IsConsoleInput() && PlatformWindows.IsUsingRasterFont())
{
_changeOutputEncoding = false;
}
Expand Down

0 comments on commit 2f4e5fa

Please sign in to comment.