Skip to content

Commit

Permalink
handle any Encoding in Console.Beep (#105094)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Jul 22, 2024
1 parent 13c75cd commit fdef8db
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/libraries/System.Console/src/System/ConsolePal.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,18 @@ public static void Beep()
{
if (!Console.IsOutputRedirected)
{
ReadOnlySpan<byte> bell = "\u0007"u8; // Windows doesn't use terminfo, so the codepoint is hardcoded.
const string BellString = "\u0007"; // Windows doesn't use terminfo, so the codepoint is hardcoded.

Span<byte> bell = stackalloc byte[10];
if (Console.OutputEncoding.TryGetBytes(BellString, bell, out int bytesWritten))
{
bell = bell.Slice(0, bytesWritten);
}
else
{
bell = Console.OutputEncoding.GetBytes(BellString);
}

int errorCode = WindowsConsoleStream.WriteFileNative(OutputHandle, bell, useFileAPIs: Console.OutputEncoding.CodePage != UnicodeCodePage);
if (errorCode == Interop.Errors.ERROR_SUCCESS)
{
Expand Down

0 comments on commit fdef8db

Please sign in to comment.