Detecting console dimensions

Is there a simple way for a ruby script to know the size of the space
it has to work with Would I be forced to use ncurses or some such?

I see that i have environment variables like COLUMNS and ROWS .. but I
don't know how to get this information into a script. For example,
ENV['ROWS'] does not work..

Yeah, I figured this.. it's almost certainly xterm that's generating
these settings.. but I wanted to work on an in intermediate solution
so that I can think about the logic associated with this knowledge.
Later I'd want to do something far more universal.

I can dream up a screen dimension-detection function, by leveraging
the ANSI features which I've got access to. (By printing certain
characters and then moving the cursor in certain ways and detecting
for them)

I want to avoid yet another dependancy.. maybe I should just have a
configuration file (constants for now) so the user can set this
information for the script.

···

On 5/20/06, Philip Hallstrom <ruby@philip.pjkh.com> wrote:

I can't help you, but you might not always have COLUMNS/ROWS. I'm a tcsh
user and I don't think I've *ever* seen those variables set when doing a
printenv...

so that's something else to consider...

Sy Ali wrote:

Is there a simple way for a ruby script to know the size of the space
it has to work with Would I be forced to use ncurses or some such?

Any particular reason not to use curses? Because it would get you what
you want really easily, and you can just drop out of curses mode again
and continue your script...

Pistos

···

--
Posted via http://www.ruby-forum.com/\.

Also remember that screen dimensions can change while the program is
running. I think ncurses has ways of dealing with this. It may be
better to bit the bullet on this one and use other people's work, it
can get quite tricky.

If you do consider Ncurses, bear in mind that it's not exactly the
same between Windows and Linux.

Les

···

On 5/20/06, Sy Ali <sy1234@gmail.com> wrote:

On 5/20/06, Philip Hallstrom <ruby@philip.pjkh.com> wrote:
> I can't help you, but you might not always have COLUMNS/ROWS. I'm a tcsh
> user and I don't think I've *ever* seen those variables set when doing a
> printenv...
>
> so that's something else to consider...

Yeah, I figured this.. it's almost certainly xterm that's generating
these settings.. but I wanted to work on an in intermediate solution
so that I can think about the logic associated with this knowledge.
Later I'd want to do something far more universal.

I can dream up a screen dimension-detection function, by leveraging
the ANSI features which I've got access to. (By printing certain
characters and then moving the cursor in certain ways and detecting
for them)

I want to avoid yet another dependancy.. maybe I should just have a
configuration file (constants for now) so the user can set this
information for the script.

Yes, there are a few reasons why I'm gun-shy.

* Learning something new (which distracts from my learning other things)
* Adding a dependancy to the script.
* Assuming ncurses works, and works the same, everywhere.

···

On 5/20/06, Pistos Christou <jesusrubsyou.5.pistos@geoshell.com> wrote:

Sy Ali wrote:
> Is there a simple way for a ruby script to know the size of the space
> it has to work with Would I be forced to use ncurses or some such?

Any particular reason not to use curses? Because it would get you what
you want really easily, and you can just drop out of curses mode again
and continue your script...

Sy Ali wrote:

Yes, there are a few reasons why I'm gun-shy.
* Learning something new (which distracts from my learning other things)
* Adding a dependancy to the script.
* Assuming ncurses works, and works the same, everywhere.

You're right that it's not everywhere. In particular, Debian (and
spinoffs) want to make curses a separate package than the Ruby package.
:frowning: But, AFAIK, it works the same everywhere with the exception of the
Windows platform.

The learning part is trivial, because I could tell you the three to five
lines you need to get the dimensions.

Anyway, hope you figure out your problem.

Pistos

···

--
Posted via http://www.ruby-forum.com/\.