PDA

View Full Version : Get terminal variables



sixten
27-11-2012, 05:40 PM
Does anyone know how i can read the $COLUMNS and $ROWS in a console application in Linux?

When i try

for i := 0 to GetEnvironmentVariableCount do
Writeln(GetEnvironmentString(i));

COLUMNS and ROWS are not listed.

I would like to somehow execute "echo $COLUMNS" and pipe the result back to the program.

Super Vegeta
28-11-2012, 06:32 AM
The first thing coming to my head is to use the (deprecated, but oh well, still works) Shell() command and invoke "echo $COLUMNS > file.txt", then read from that file. Dirty as hell, I know. :P

sixten
30-11-2012, 05:16 PM
Thanks for your reply.

That could work if i knew how to get a signal everytime the terminal was resized. As it is now i use ncurses Getwinxy in a loop. Writing to a file hundreds of times per second is not optimal. I can't believe a simple thing like this isn't available in a easy way in the crt unit, pretty basic stuff one would think.

wodzu
29-12-2012, 09:49 AM
I haven't touched Linux for years but maybe you could use this tput tool as described in this post: http://stackoverflow.com/questions/2203437/how-to-get-linux-console-columns-and-rows-from-php-cli