Skip to content

Conversation

@karakasa
Copy link
Contributor

Fix #102211

The behavioral breaking change would require a later document change.

karakasa added 2 commits May 25, 2024 16:44
implement Console.Beep via BEL char,
rather than the original pinvoke.
stdout/err when redirected
@ghost ghost added the area-System.Console label May 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 25, 2024
@karakasa karakasa marked this pull request as ready for review May 25, 2024 12:12
@jkotas jkotas added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label May 25, 2024
@dotnet-policy-service
Copy link
Contributor

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@dotnet-policy-service dotnet-policy-service bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label May 25, 2024
@karakasa
Copy link
Contributor Author

@jkotas Could you kindly send the DL for me?

@jkotas
Copy link
Member

jkotas commented May 25, 2024

@jkotas Could you kindly send the DL for me?

The breaking change notification should be done by @dotnet/area-system-console owners once the PR is merged.

@karakasa
Copy link
Contributor Author

The breaking change notification should be done by @dotnet/area-system-console owners once the PR is merged.

Ah, sorry. Per the bot message I thought this needs to be done by me.

@stephentoub stephentoub requested a review from adamsitnik July 9, 2024 15:41
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karakasa thank you for providing high quality contribution (I really liked the tests)!

@adamsitnik adamsitnik merged commit 06c8a3c into dotnet:main Jul 15, 2024
@adamsitnik adamsitnik added this to the 9.0.0 milestone Jul 15, 2024
@adamsitnik
Copy link
Member

jkotas added the breaking-change label on May 25

@jkotas it's more like a bug fix to me. Do you really believe we should provide breaking change docs for this PR?


if (!Console.IsOutputRedirected)
{
Console.Out.Write(BellCharacter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break beeps if someone has used Console.SetOut to hook console writing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console.SetOut will make Console.IsOutputRedirected return true.

Copy link
Member

@stephentoub stephentoub Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console.SetOut will make Console.IsOutputRedirected return true.

That is not the case.

using System.Text;

var ms = new MemoryStream();
var orig = Console.Out;
Console.SetOut(new StreamWriter(ms) { AutoFlush = true });
Console.WriteLine(Console.IsOutputRedirected);
Console.SetOut(orig);
Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));

That prints false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just tried this:

Console.SetOut(new StringWriter());
Console.Beep();

It used to beep. With this PR, it no longer does.

@adamsitnik

@jkotas
Copy link
Member

jkotas commented Jul 15, 2024

Do you really believe we should provide breaking change docs for this PR?

Console.Beep is going to produce whatever jingle is configured for the bell character in your Windows or terminal settings. It is going to be very different sound from the Beep that it produces today. I think it qualifies as a breaking change.

Run the following to see the difference:

Console.Beep();

Thread.Sleep(1000);

const char BellCharacter = '\u0007';
Console.Out.Write(BellCharacter);

Also, the docs need to be updated. https://learn.microsoft.com/en-us/dotnet/api/system.console.beep says that "the beep plays at a frequency of 800 hertz for a duration of 200 milliseconds." and "Beep wraps a call to the Windows Beep function" that is not going to be the case after this change.

return;
}

if (!Console.IsErrorRedirected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Unix version of this function does not write to stderr. Should we try to be consistent between Windows and Unix - produce the bell character for !Console.IsOutputRedirected only?


if (!Console.IsOutputRedirected)
{
Console.Out.Write(BellCharacter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really want to do what this PR is doing, we shouldn't be going to Console.Out. We should instead do what the unix implementation does, which is going directly to the stdout handle / file descriptor, such that it won't target Console.Out and any custom writer it may have been redirected to, e.g.

=> WriteTerminalAnsiString(value, Interop.Sys.FileDescriptors.STDOUT_FILENO, mayChangeCursorPosition: false);

In the meantime, though, I suggest this PR be reverted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime, though, I suggest this PR be reverted.

I am going to give it a try and if I can not implement it in 1h I am going to revert the PR. Does that sound OK @stephentoub ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I'm still not sure about the premise of this change. Isn't it strange that Beep with and without parameters are now fundamentally different? This goes to Jan's points about this being a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I'm still not sure about the premise of this change.

#102211 (comment)

Copy link
Member

@stephentoub stephentoub Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I'm still not sure about the premise of this change.

#102211 (comment)

I know what's written in the issue. What I meant was I'm not sure it's a desirable change, given the other Beep overload and back compat. It is a breaking change to be documented, at a minimum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've sent #104966

@github-actions github-actions bot locked and limited conversation to collaborators Aug 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Console breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. community-contribution Indicates that the PR has been added by a community member needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Console]::Beep() does not activate "Bell Notifications"

4 participants