Followup: I found this code, which is supposed to do the trick:

#!/usr/bin/env ruby

TIOCGWINSZ = 0x5413

def terminal_size
     rows, cols = 25, 80
     buf = [0, 0, 0, 0].pack("SSSS")
     if STDOUT.ioctl(TIOCGWINSZ, buf) >= 0 then
         rows, cols, row_pixels, row_pixels, col_pixels =  
buf.unpack("SSSS")[0..1]
     end
     return [rows, cols]
end

print terminal_size


But when I run it, I get :

./term_size.rb:9:in `ioctl': Inappropriate ioctl for device  
(Errno::ENOTTY)
         from ./term_size.rb:9:in `terminal_size'
         from ./term_size.rb:15

This is on OS X 10.5, tried with both terminal and iterm. Any ideas?

Thanks,
Ken


On Sep 25, 2008, at 5:33 PM, Kenneth McDonald wrote:

> I'd like to be able to print to terminal and do some reasonable  
> formatting, without going to the trouble of learning curses. I  
> simply need to know the dimensions of the terminal, but that info  
> doesn't appear to be available in the ENV variables (which is what  
> I'd expected.) Is there a way to get this info?
>
> Thanks,
> Ken
>