Skip to content
Merged
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
20 changes: 20 additions & 0 deletions Terminal.Gui/Drivers/WindowsHelpers/WindowsVTInputHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ internal sealed class WindowsVTInputHelper : IDisposable
[DllImport ("kernel32.dll")]
private static extern uint GetConsoleCP ();

[DllImport ("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCP (uint wCodePageID);

#endregion

private const int ERROR_NOT_FOUND = 1168;
Expand All @@ -68,6 +71,22 @@ internal sealed class WindowsVTInputHelper : IDisposable
private uint _originalConsoleMode;
private bool _disposed;

private const uint CP_UTF8 = 65001;

private readonly uint _originalConsoleCP;

public WindowsVTInputHelper ()
{
_originalConsoleCP = GetConsoleCP ();

if (_originalConsoleCP == CP_UTF8 || SetConsoleCP (CP_UTF8))
{
return;
}
int error = Marshal.GetLastWin32Error ();
Logging.Warning ($"{nameof (WindowsVTInputHelper)}: Failed to set console input code page to UTF-8. Win32 error: {error}");
}

/// <summary>
/// Gets whether VTS input mode was successfully enabled.
/// </summary>
Expand Down Expand Up @@ -238,6 +257,7 @@ public void Restore ()

try
{
SetConsoleCP (_originalConsoleCP);
Comment thread
BDisp marked this conversation as resolved.
SetConsoleMode (InputHandle, _originalConsoleMode);
IsEnabled = false;
}
Expand Down
Loading