# Detecting console dimensions

**URL:** <https://www.ruby-forum.com/t/detecting-console-dimensions/61109>\
**Category:** Ruby\
**Created:** [May 20, 2006, 6:39am UTC](https://www.ruby-forum.com/t/detecting-console-dimensions/61109 "2006-05-20T06:39:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sy\_Ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Sy\_Ali](https://www.ruby-forum.com/u/Sy_Ali)\
**Post date:** [May 20, 2006, 6:39am UTC](https://www.ruby-forum.com/t/detecting-console-dimensions/61109/1 "2006-05-20T06:39:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Sy\_Ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Sy\_Ali](https://www.ruby-forum.com/u/Sy_Ali)\
**Post date:** [May 21, 2006, 4:47am UTC](https://www.ruby-forum.com/t/detecting-console-dimensions/61109/2 "2006-05-21T04:47:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sy\_Ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Sy\_Ali](https://www.ruby-forum.com/u/Sy_Ali)\
**Post date:** [May 21, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/detecting-console-dimensions/61109/3 "2006-05-21T15:32:21Z")

</div>

On 5/20/06, Pistos C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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…

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.

---

<div class="post-metadata">

**Author:** ![Sy\_Ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Sy\_Ali](https://www.ruby-forum.com/u/Sy_Ali)\
**Post date:** [May 21, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/detecting-console-dimensions/61109/4 "2006-05-21T23:29:48Z")

</div>

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.  
☹ 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
