-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Add sapi_windows_console_size() #17057
base: master
Are you sure you want to change the base?
Conversation
This function is supposed to retrieve the width and height of a console window on Windows. It expects a single stream argument, and if that is a console, returns its width and height as two element array (aka. pair). On failure the function returns false.
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0); | ||
} else { | ||
php_error_docref(NULL, E_WARNING, "not able to analyze the specified stream"); |
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.
After reading https://bugs.php.net/bug.php?id=79805, I think the warning should be dropped (we only warn about this when sapi_windows_vt100_support()
is used as setter).
if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0); | ||
} else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL) == SUCCESS) { | ||
php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fileno, 0); |
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 had copied this code from sapi_windows_vt100_support()
without thinking. Now I had a closer look, and wondered why we even try to cast to PHP_STREAM_AS_FD_FOR_SELECT
(we don't actually want to select). Looking at the implementation of php_stdiop_cast()
it's clear: this cast won't flush (what we indeed don't want), but other possibly castable stream might not implement PHP_STREAM_AS_FD_FOR_SELECT
. So these two cast attempts make some sense (although they rely on a leaky abstraction).
Then I wondered why we first check if we can cast and then actually do cast. Regarding the implementation that makes not much sense, but for the sake of abstraction it is correct. On the other hand, asking whether we can cast to PHP_STREAM_AS_FD
actually flushes (for stdio stream), so this is somewhat (s/somewhat/completely) broken anyway.
Well, probably best to leave as is for now.
Maybe I'm doing a stupid suggestion, but I suppose that on Unix-likes we can also have this kind of function. I don't know if it exists yet, but:
|
IIRC, that's done with php-src/sapi/phpdbg/phpdbg_utils.c Lines 350 to 387 in e1e2089
|
Thanks @nielsdos, that makes perfect sense. And thank you @NattyNarwhal; I wasn't aware that this is already implemented for phpdbg. |
I don't really get why it's named sapi_... when it's a stream funcion but there is already If it's used in phpdbg, it would make sense to use a common function for this. |
This function is supposed to retrieve the width and height of a console window on Windows. It expects a single stream argument, and if that is a console, returns its width and height as two element array (aka. pair). On failure the function returns false.
outputs something like
I'm just dropping this here for discussion.
TODO: