When writing an ANSI escape code to the console like this:
julia> print(stdout, "\033[14t");
One gets an answer back that is also written to the console. In this case we get
which is the width and height of my console.
Now I was wondering how I can use this to query for my console size, i.e how can I ensure that the answer is not directly written to the console but to some variable and how would I do such thing in a thread save way, so that other processes that might try to read from stdin do not interfere with my answer.
Maybe you can use
Unfortunately that only gives me the number of rows/columns but I need the number of pixels. But I looked into the code for
displaysize and it uses
TIOCGWINSZ internally (which is the second approach I am exploring right now). That call actually returns the number of pixels, but that information is then just thrown away.
Oh, then I misunderstood your question. Why do you want the pixel size of the terminal? I.e. what will you use the information for? Just out of curiosity, I don’t know of a way to retrieve that information.
It s for a package of mine that allows one to display images in a terminal when using the Kitty terminal emulator. So I thought It might be a good idea to have the ability to scale some output to the width of the terminal.
Also, there might be other information that I could get out using escape sequences, for example the name of the terminal emulator.