Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Console.SetWindowSize() for linux #75824

Merged
merged 12 commits into from
Nov 8, 2022

Conversation

HJLeee
Copy link
Contributor

@HJLeee HJLeee commented Sep 19, 2022

Implement Console.SetWindowSize() using the same system call with ConsoleGetWindowSize() (ioctl w/ set param TIOCSWINSZ).

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Sep 19, 2022
@ghost
Copy link

ghost commented Sep 19, 2022

Tagging subscribers to this area: @dotnet/area-system-console
See info in area-owners.md if you want to be subscribed.

Issue Details

Implement Console.SetWindowSize() using the same system call with ConsoleGetWindowSize() (ioctl w/ set param TIOCSWINSZ).

Author: HJLeee
Assignees: -
Labels:

area-System.Console, new-api-needs-documentation

Milestone: -

@HJLeee HJLeee changed the title Impl Console.SetWindowSize() for linux Implement Console.SetWindowSize() for linux Sep 19, 2022
@HJLeee HJLeee marked this pull request as ready for review September 20, 2022 00:12
@HJLeee
Copy link
Contributor Author

HJLeee commented Sep 29, 2022

@stephentoub Would you review this please?

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.

@HJLeee thank you for your contribution! PTAL at my comments.

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.

HI @HJLeee

Please excuse me for the delay in the review.

I've cloned your fork and tried to add some new console manual tests:

        [ConditionalFact(nameof(ManualTestsEnabled))]
        [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Browser, iOS, MacCatalyst, or tvOS.")]
        public static void ResizeTest()
        {
            bool wasResized = false;

            using (ManualResetEvent manualResetEvent = new(false))
            using (PosixSignalRegistration.Create(PosixSignal.SIGWINCH,
               ctx =>
               {
                   wasResized = true;
                   Assert.Equal(PosixSignal.SIGWINCH, ctx.Signal);
                   manualResetEvent.Set();
               }))
            {
                int widthBefore = Console.WindowWidth;
                int heightBefore = Console.WindowHeight;

                Assert.False(wasResized);

                Console.SetWindowSize(widthBefore / 2, heightBefore / 2);

                Assert.True(manualResetEvent.WaitOne(TimeSpan.FromMilliseconds(50)));
                Assert.True(wasResized);
                Assert.Equal(widthBefore / 2, Console.WindowWidth );
                Assert.Equal(heightBefore / 2, Console.WindowHeight );

                try
                {
                    AssertUserExpectedResults("terminal window getting two times smaller?");
                }
                finally
                {
                    Console.SetWindowSize(widthBefore, heightBefore);
                }
            }
        }

The problem is that the value is set correctly (and we get signal notification), but Terminal size does not change in visible way (I've tested GNOME and xterm terminals on Ubuntu). According to this StackOverflow answer it does not work by design on most of the terminals and we should use escape sequences to get it working. We are already using some:

private static void WriteResetColorString()
{
if (ConsoleUtils.EmitAnsiColorCodes)
{
WriteStdoutAnsiString(TerminalFormatStringsInstance.Reset);
}
}

Which Terminal have you used for testing?

To run any dotnet app using your local build of dotnet/runtime you need to find corerun:

find -name corerun

and run it by providing the path to the dll:

./artifacts/bin/testhost/net7.0-Linux-Release-x64/shared/Microsoft.NETCore.App/8.0.0/corerun $pathTo.dll

@adamsitnik adamsitnik self-assigned this Oct 28, 2022
@adamsitnik adamsitnik added this to the 8.0.0 milestone Oct 28, 2022
@HJLeee
Copy link
Contributor Author

HJLeee commented Oct 31, 2022

Hi, Thank you for the testcase and review.

Which Terminal have you used for testing?

I've used my ubuntu 22.04 with screen-256color TERM and checked effectiveness with nvim as below.
You can see nvim uses the value I set for testing.

· ~/dotnet/tests/winsize $ cat Program.cs
// See https://aka.ms/new-console-template for more information
Console.SetWindowSize(80,30);
Console.WriteLine("Width: {0}, Height: {1}", Console.WindowWidth, Console.WindowHeight);

캡처

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

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.

LGTM, big thanks for your contribution @HJLeee !

@adamsitnik
Copy link
Member

src/libraries/apicompat/ApiCompat.proj(50,5): error CP0014: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot remove attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")' from 'System.Console.WindowHeight.get'.

@ViktorHofer we want to introduce this change on purpose, what is needed to make the CI green in such case?

@ViktorHofer
Copy link
Member

Replied offline:

You will need to add the compatibility difference to the suppression file that is used when comparing net7.0 against net6.0: runtime/ApiCompatBaseline.NetCoreAppLatestStable.xml at main · dotnet/runtime (github.com).
You can either hand-edit it or use the following command to update it: dotnet.cmd src/libraries/apicompat --no-dependencies /p:GenerateCompatibilitySuppressionFile=true

@adamsitnik
Copy link
Member

@ViktorHofer I've done that and pushed the changes. I can perform a full clean build now (build -c Release -subset clr+libs+libs.tests) on both Windows and Linux, but the CI is still failing with the old error message (before the fix I was getting the same error locally). Do you have any idea why?

@ViktorHofer
Copy link
Member

@ViktorHofer I've done that and pushed the changes. I can perform a full clean build now (build -c Release -subset clr+libs+libs.tests) on both Windows and Linux, but the CI is still failing with the old error message (before the fix I was getting the same error locally). Do you have any idea why?

Looking now

@ViktorHofer
Copy link
Member

The build is passing for me locally as well and I diffed the binlogs from the failing run and the local one. There aren't any differences that would explain this behavior.

After spending some time on it, I just noticed that CI wasn't triggered for your commit :(

@ViktorHofer
Copy link
Member

/azp run dotnet-linker-tests

@ViktorHofer
Copy link
Member

/azp run runtime-dev-innerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ViktorHofer
Copy link
Member

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ViktorHofer
Copy link
Member

/azp run runtime-staging

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adamsitnik adamsitnik merged commit 32c7147 into dotnet:main Nov 8, 2022
@HJLeee
Copy link
Contributor Author

HJLeee commented Nov 8, 2022

Wow. Thank you for APICompat and CI stuff. 😄

@HJLeee HJLeee deleted the linux_console branch November 8, 2022 09:24
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Console community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants