From: James Edward Gray II Date: 2007-08-08T04:39:00+09:00 Subject: Re: Need Solaris Help On Aug 7, 2007, at 2:17 PM, Coey Minear wrote: > ronald braswell writes: >> On 8/7/07, Gregory Brown wrote: >>> >>> On 8/7/07, James Edward Gray II wrote: >>>> I'm told the following bit of code doesn't work on Solaris: >>>> >>>> # A Unix savvy method to fetch the console columns, and >>>> rows. >>>> def terminal_size >>>> `stty size`.split.map { |x| x.to_i }.reverse >>>> end >>>> >>>> HighLine makes use of this method as does Capistrano by >>>> extension, so >>>> we need find a portable solution. >>> >>> Ruport vendors this chunk of code, so sorry for the 'me too', but >>> me too! >>> >>> >> This is not pretty but it works on my Solaris 10 x64 box. But >> you may have >> been looking >> for something more elegant. >> >> if `stty` =~ /.*\brows = (\d+).*\bcolumns = (\d+)/ >> rows = $1 >> columns = $2 >> end >> >> Ron > > Here's my stab at a cross-platform implementation: > > def terminal_size > if /solaris/ =~ RUBY_PLATFORM > output = `stty` > [output.match('columns = (\d+)')[1].to_i, > output.match('rows = (\d+)')[1].to_i] > else > `stty size`.split.map { |x| x.to_i }.reverse > end > end > > I did a quick test on Solaris (9 and 10), FreeBSD and Linux, and got > the same results in every case. (No guarantees on AIX, HP-UX, etc.) Thanks all. I appreciate the help. James Edward Gray II