Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Console] Refactor isTtySupported()#46971
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedJul 18, 2022
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
| if (null ===$isTtySupported &&\function_exists('proc_open')) { | ||
| $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file','/dev/tty','r'], ['file','/dev/tty','w'], ['file','/dev/tty','w']],$pipes); | ||
| if (null ===$isTtySupported) { | ||
| $isTtySupported = ('/' === \DIRECTORY_SEPARATOR &&stream_isatty(\STDOUT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
IIUC,stream_isatty supports Windows, so do we need the'/' === \DIRECTORY_SEPARATOR part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Windows does not supportecho 1 >/dev/null, so we need'/' === \DIRECTORY_SEPARATOR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I don't get it, sorry. Are you saying thatstream_isatty is usingecho 1 >/dev/null behind the scenes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sorry!
Windows does not supportecho 1 >/dev/null, so we need'/' === \DIRECTORY_SEPARATOR.
Usestream_isatty() to determine if tty is supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
but you don't useecho 1 >/dev/null anymore, andstream_isatty supports windows natively. So this check become useless, isn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
To be clear, I think having$isTtySupported = stream_isatty(\STDOUT); is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
getCurrentPosition() does not support in windows.
stream_isatty(\STDOUT) may also returntrue in windows.
php:
$cursor =newCursor($output);var_dump($cursor->getCurrentPosition());
log:
'stty' is not recognized as an internal or external command,operable program or batch file.'stty' is not recognized as an internal or external command,operable program or batch file.'stty' is not recognized as an internal or external command,operable program or batch file.array(2) { [0]=> NULL [1]=> NULL}fabpot commentedJul 21, 2022
Thank you@Yurunsoft. |
jsandfordhughes commentedJan 30, 2023
This PR has broken the isTtySupported specifically in PHPStorm using the built in run window on a Mac M1 Pro Chip. By manually changing the method to the old code, everything works fine. How can we debug the issue here? |
Yurunsoft commentedJan 31, 2023
I run this code in Windows+PHPStorm 2022.3.1+wsl and the result is consistent. Could you test this code? <?phpdeclare(strict_types=1);var_dump((bool) @proc_open('echo 1 >/dev/null', [['file','/dev/tty','r'], ['file','/dev/tty','w'], ['file','/dev/tty','w']],$pipes));var_dump(stream_isatty(\STDOUT)); |
audiojames commentedFeb 6, 2023
jsandfordhughes commentedFeb 6, 2023
Thanks for helping@audiojames |


stream_isatty():https://www.php.net/manual/en/function.stream-isatty.php (PHP 7 >= 7.2.0, PHP 8)