Computer Science Canada Getting terminal width |
Author: | DtY [ Sat Jun 06, 2009 11:20 pm ] |
Post subject: | Getting terminal width |
In irb, I'm able to get the width of the terminal using ENV['COLUMNS'], however, ENV doesn't seem to have that key when running a script. Is there any other way to get the size without installing some extra libraries? |
Author: | rdrake [ Sun Jun 07, 2009 12:33 am ] | ||
Post subject: | RE:Getting terminal width | ||
Don't think so. Check out Ruby Ncurses, methinks it can do what you want. You can also use the back ticks in order to execute something on the command line, then grab that in your script.
|
Author: | DtY [ Sun Jun 07, 2009 1:02 am ] |
Post subject: | RE:Getting terminal width |
You sure that that line's right? irb(main):002:0> `echo ENV['COLUMNS']` => "ENV[COLUMNS]\n" And ncurses is more than I want to set up, my program is just showing a progress bar, so I'd rather use a fixed with than use ncurses. |
Author: | rdrake [ Sun Jun 07, 2009 10:40 am ] | ||
Post subject: | RE:Getting terminal width | ||
|
Author: | DtY [ Sun Jun 07, 2009 12:50 pm ] |
Post subject: | RE:Getting terminal width |
Same thing, works in irb, but not ruby: irb(main):001:0> `echo $COLUMNS` => "80\n" [jeff@localhost ~]$ ruby p `echo $COLUMNS`[CTRL+D] "\n" |
Author: | rdrake [ Sun Jun 07, 2009 1:17 pm ] | ||
Post subject: | RE:Getting terminal width | ||
This gem comes from the HighLiner project:
Of course instead of just stealing the method you can also have users install the gem which is just called "highliner." It also includes a Win32 version of the terminal_size() method. |
Author: | DtY [ Sun Jun 07, 2009 1:25 pm ] |
Post subject: | RE:Getting terminal width |
That one works, thanks you ![]() |