I know that it’s possible to get the terminal size on Linux using the following :
$cols = `tput cols`; $lines = `tput lines`;
But on windows, the only solution I found is the following: using the command mode con
. The problem with this is that I can’t even parse it because it’s translated and depending on the language of the OS.
So my question is simple: how to get terminal size on windows programmatically with PHP?
Advertisement
Answer
See https://github.com/symfony/symfony/blob/v5.2.1/src/Symfony/Component/Console/Terminal.php for the implementation of such retrieval in the Symfony framework. It does not only parse the mode CON
output but also tries using the ANSICON
env variable to support the ANSICON terminal. The parsing of the mode CON
output itself is around line 135 of the file.