Skip to content

Commit be211cb

Browse files
committed
first attempt: use Console.Out, but only when s_isOutTextWriterRedirected is false (it's set by Console.SetOut)
1 parent 25a5085 commit be211cb

File tree

7 files changed

+10
-22
lines changed

7 files changed

+10
-22
lines changed

src/libraries/System.Console/src/System/Console.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public static string Title
538538
[UnsupportedOSPlatform("tvos")]
539539
public static void Beep()
540540
{
541-
ConsolePal.Beep();
541+
ConsolePal.Beep(s_isOutTextWriterRedirected);
542542
}
543543

544544
[SupportedOSPlatform("windows")]

src/libraries/System.Console/src/System/ConsolePal.Android.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static string Title
9494
set => throw new PlatformNotSupportedException();
9595
}
9696

97-
public static void Beep() => throw new PlatformNotSupportedException();
97+
public static void Beep(bool _) => throw new PlatformNotSupportedException();
9898

9999
public static void Beep(int frequency, int duration) => throw new PlatformNotSupportedException();
100100

src/libraries/System.Console/src/System/ConsolePal.Unix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static string Title
205205
}
206206
}
207207

208-
public static void Beep()
208+
public static void Beep(bool _)
209209
{
210210
if (!Console.IsOutputRedirected)
211211
{

src/libraries/System.Console/src/System/ConsolePal.Wasi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static string Title
9696
set => throw new PlatformNotSupportedException();
9797
}
9898

99-
public static void Beep() => throw new PlatformNotSupportedException();
99+
public static void Beep(bool _) => throw new PlatformNotSupportedException();
100100

101101
public static void Clear() => throw new PlatformNotSupportedException();
102102
public static void SetCursorPosition(int left, int top) => throw new PlatformNotSupportedException();

src/libraries/System.Console/src/System/ConsolePal.WebAssembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static string Title
155155
set => throw new PlatformNotSupportedException();
156156
}
157157

158-
public static void Beep() => throw new PlatformNotSupportedException();
158+
public static void Beep(bool _) => throw new PlatformNotSupportedException();
159159

160160
public static void Beep(int frequency, int duration) => throw new PlatformNotSupportedException();
161161

src/libraries/System.Console/src/System/ConsolePal.Windows.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -675,30 +675,18 @@ public static unsafe string Title
675675
}
676676
}
677677

678-
public static void Beep()
678+
public static void Beep(bool isOutTextWriterRedirected)
679679
{
680680
const char BellCharacter = '\u0007'; // Windows doesn't use terminfo, so the codepoint is hardcoded.
681681

682-
if (!Console.IsOutputRedirected)
682+
if (!Console.IsOutputRedirected && !isOutTextWriterRedirected)
683683
{
684684
Console.Out.Write(BellCharacter);
685-
return;
686685
}
687-
688-
if (!Console.IsErrorRedirected)
686+
else
689687
{
690-
Console.Error.Write(BellCharacter);
691-
return;
688+
Interop.Kernel32.Beep(frequency: 800, duration: 200);
692689
}
693-
694-
BeepFallback();
695-
}
696-
697-
private static void BeepFallback()
698-
{
699-
const int BeepFrequencyInHz = 800;
700-
const int BeepDurationInMs = 200;
701-
Interop.Kernel32.Beep(BeepFrequencyInHz, BeepDurationInMs);
702690
}
703691

704692
public static void Beep(int frequency, int duration)

src/libraries/System.Console/src/System/ConsolePal.iOS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static string Title
9999
set => throw new PlatformNotSupportedException();
100100
}
101101

102-
public static void Beep() => throw new PlatformNotSupportedException();
102+
public static void Beep(bool _) => throw new PlatformNotSupportedException();
103103

104104
public static void Beep(int frequency, int duration) => throw new PlatformNotSupportedException();
105105

0 commit comments

Comments
 (0)