Skip to content

[Console] Get dimensions from stty on windows if possible #32763

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

Merged
merged 1 commit into from
Sep 13, 2019
Merged

[Console] Get dimensions from stty on windows if possible #32763

merged 1 commit into from
Sep 13, 2019

Conversation

rtek
Copy link
Contributor

@rtek rtek commented Jul 26, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Console\Terminal is modified to extract width/height settings to from stty on windows if possible. Previously such values were extracted from mode CON. If another terminal is in use (eg, gitbash) then the incorrect values would be applied.

@rtek
Copy link
Contributor Author

rtek commented Jul 26, 2019

Had to refactor Terminal into a singleton otherwise it couldn't be tested when mocking out the env. It was practically one already due to the static properties.

@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Jul 26, 2019
@fabpot
Copy link
Member

fabpot commented Jul 27, 2019

@rtek Tests must not impact our code. I would highly suggest to remove the singleton and find a way to test the code in another way.

@rtek
Copy link
Contributor Author

rtek commented Jul 27, 2019

@fabpot Understood - reverted the public API changes.

Re master, Terminal appears to be short-circuited via envvars after application initialization Application.php:117 Terminal.php:26 so it's basically global state. It's used by various classes which contain their own terminal capability check as well, so it's a candidate for consolidation. I offer to put some effort into this if there is an appetite.

private static $width;
private static $height;
private $width;
private $height;
Copy link
Member

Choose a reason for hiding this comment

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

I think they were static as a way to cache the values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but only in a non application context. Application sets env COLUMNS/LINES from the calculated values in Terminal, which then provides caching since Terminal always checks the env first. Only those who instantiate Terminal outside of an application and did not reuse the instance would lose the cache. If this is not acceptable then I would have to use reflection to get the test coverage - is that OK?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at the code base, I can see that we are instantiating a Terminal instance several times (the instance is not shared).

@rtek
Copy link
Contributor Author

rtek commented Aug 17, 2019

Reverted to maintain the static cache convention and used reflection to test. Test failures on unrelated component.

@chalasr chalasr changed the base branch from 4.3 to 3.4 September 13, 2019 12:37
@chalasr chalasr modified the milestones: 4.3, 3.4 Sep 13, 2019
@chalasr
Copy link
Member

chalasr commented Sep 13, 2019

PR target changed from 4.3 to 3.4 as the bug also exists there.
Also updated QuestionHelper to make it uses the internal Terminal::hasSttyAvailable() so that we don't have duplication.

@fabpot
Copy link
Member

fabpot commented Sep 13, 2019

Thank you @rtek.

fabpot added a commit that referenced this pull request Sep 13, 2019
…(rtek)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Get dimensions from stty on windows if possible

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

`Console\Terminal` is modified to extract width/height settings to from `stty` on windows if possible. Previously such values were extracted from `mode CON`. If another terminal is in use (eg, gitbash) then the incorrect values would be applied.

Commits
-------

5265080 [Console] Get dimensions from stty on windows if possible
@fabpot fabpot merged commit 5265080 into symfony:3.4 Sep 13, 2019
This was referenced Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants