Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Need Solaris Help

Reply
Thread Tools

Need Solaris Help

 
 
James Edward Gray II
Guest
Posts: n/a
 
      08-07-2007
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.

Can anyone provide an equivalent technique that works on Solaris?

Thanks.

James Edward Gray II

 
Reply With Quote
 
 
 
 
Gregory Brown
Guest
Posts: n/a
 
      08-07-2007
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!

 
Reply With Quote
 
 
 
 
Douglas F Shearer
Guest
Posts: n/a
 
      08-07-2007
On 7 Aug 2007, at 19:20, James Edward Gray II wrote:

> I'm told the following bit of code doesn't work on Solaris:
> `stty size`.split.map { |x| x.to_i }.reverse
>
> James Edward Gray II
>


If it helps, the output from stty looks like the following:

-bash-3.00# stty size
unknown mode: size
-bash-3.00# stty
speed 38400 baud; -parity
rows = 24; columns = 80; ypixels = 0; xpixels = 0;
eol = -^?; eol2 = -^?; swtch = <undef>; flush = -^?; lnext = -^?;
brkint -inpck -istrip icrnl imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten

Had a quick look at the man pages, there doesn't seem to be an alias
for size.

The man pages are also on the Sun site here: http://docs.sun.com/app/
docs/doc/816-5165/6mbb0m9tb?a=view

Hope this is of some help.

Douglas F Shearer
http://douglasfshearer.com

 
Reply With Quote
 
Alex Young
Guest
Posts: n/a
 
      08-07-2007
Douglas F Shearer wrote:
> On 7 Aug 2007, at 19:20, James Edward Gray II wrote:
>
>> I'm told the following bit of code doesn't work on Solaris:
>> `stty size`.split.map { |x| x.to_i }.reverse
>>
>> James Edward Gray II
>>

>
> If it helps, the output from stty looks like the following:
>
> -bash-3.00# stty size
> unknown mode: size
> -bash-3.00# stty
> speed 38400 baud; -parity
> rows = 24; columns = 80; ypixels = 0; xpixels = 0;
> eol = -^?; eol2 = -^?; swtch = <undef>; flush = -^?; lnext = -^?;
> brkint -inpck -istrip icrnl imaxbel onlcr tab3
> echo echoe echok echoctl echoke iexten
>

On FreeBSD:

[alex@panama ~/noodling/rubinius]$ stty
speed 38400 baud;
lflags: echoe echoke echoctl pendin
oflags: -oxtabs
cflags: cs8 -parenb

No rows or columns. How about stty -a?

[alex@panama ~/noodling/rubinius]$ stty -a
speed 38400 baud; 62 rows; 157 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk
brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q;
status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;


--
Alex

 
Reply With Quote
 
Tim Pease
Guest
Posts: n/a
 
      08-07-2007
On 8/7/07, James Edward Gray II <> wrote:
>
> Can anyone provide an equivalent technique that works on Solaris?
>


$ cat t.rb
def terminal_size
m = %r/rows\s(?:=\s)?(\d+);.*columns\s(?:=\s)?(\d+);/.match(`stty -a`)
[Integer(m[2]), Integer(m[1])]
end

puts terminal_size.inspect

$ uname -a
SunOS hedwig 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-1500

$ ruby t.rb
[80, 36]


And on the Linux box ...

$ uname -a
Linux pong 2.6.21-1.3228.fc7 #1 SMP Tue Jun 12 15:37:31 EDT 2007 i686
i686 i386 GNU/Linux

$ ruby t.rb
[80, 24]


Blessings,
TwP

 
Reply With Quote
 
Tim Pease
Guest
Posts: n/a
 
      08-07-2007
On 8/7/07, Alex Young <> wrote:
>
> [alex@panama ~/noodling/rubinius]$ stty -a
> speed 38400 baud; 62 rows; 157 columns;


Leave it to BSD to do everything backwards!

TwP

 
Reply With Quote
 
Alex Young
Guest
Posts: n/a
 
      08-07-2007
Tim Pease wrote:
> On 8/7/07, James Edward Gray II <> wrote:
>> Can anyone provide an equivalent technique that works on Solaris?
>>

>
> $ cat t.rb
> def terminal_size
> m = %r/rows\s(?:=\s)?(\d+);.*columns\s(?:=\s)?(\d+);/.match(`stty -a`)
> [Integer(m[2]), Integer(m[1])]
> end
>
> puts terminal_size.inspect
>
> $ uname -a
> SunOS hedwig 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Blade-1500
>
> $ ruby t.rb
> [80, 36]
>
>
> And on the Linux box ...
>
> $ uname -a
> Linux pong 2.6.21-1.3228.fc7 #1 SMP Tue Jun 12 15:37:31 EDT 2007 i686
> i686 i386 GNU/Linux
>
> $ ruby t.rb
> [80, 24]
>

How's this:

[alex@panama ~/noodling/ruby]$ ruby t.rb
[157, 62]
[alex@panama ~/noodling/ruby]$ cat t.rb
def terminal_size
%r{([^;]*rows[^;]*([^;]*columns[^;]*}.match(`stty
-a`)[1..-1].map{|i| i.gsub(/\D/, '').to_i}.reverse
end

puts terminal_size.inspect


'Scuse the line break, but it works on FreeBSD, Linux and Cygwin+OCI...

--
Alex

 
Reply With Quote
 
Coey Minear
Guest
Posts: n/a
 
      08-07-2007
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.)

Coey


 
Reply With Quote
 
James Edward Gray II
Guest
Posts: n/a
 
      08-07-2007
On Aug 7, 2007, at 1:54 PM, Alex Young wrote:

> Douglas F Shearer wrote:
>> On 7 Aug 2007, at 19:20, James Edward Gray II wrote:
>>> I'm told the following bit of code doesn't work on Solaris:
>>> `stty size`.split.map { |x| x.to_i }.reverse
>>>
>>> James Edward Gray II
>>>

>> If it helps, the output from stty looks like the following:
>> -bash-3.00# stty size
>> unknown mode: size
>> -bash-3.00# stty
>> speed 38400 baud; -parity
>> rows = 24; columns = 80; ypixels = 0; xpixels = 0;
>> eol = -^?; eol2 = -^?; swtch = <undef>; flush = -^?; lnext = -^?;
>> brkint -inpck -istrip icrnl imaxbel onlcr tab3
>> echo echoe echok echoctl echoke iexten

> On FreeBSD:


I assume the current code (using `stty size`) works on FreeBSD. Does
it not?

James Edward Gray II

 
Reply With Quote
 
Alex Young
Guest
Posts: n/a
 
      08-07-2007
James Edward Gray II wrote:
> On Aug 7, 2007, at 1:54 PM, Alex Young wrote:
>
>> Douglas F Shearer wrote:
>>> On 7 Aug 2007, at 19:20, James Edward Gray II wrote:
>>>> I'm told the following bit of code doesn't work on Solaris:
>>>> `stty size`.split.map { |x| x.to_i }.reverse
>>>>
>>>> James Edward Gray II
>>>>
>>> If it helps, the output from stty looks like the following:
>>> -bash-3.00# stty size
>>> unknown mode: size
>>> -bash-3.00# stty
>>> speed 38400 baud; -parity
>>> rows = 24; columns = 80; ypixels = 0; xpixels = 0;
>>> eol = -^?; eol2 = -^?; swtch = <undef>; flush = -^?; lnext = -^?;
>>> brkint -inpck -istrip icrnl imaxbel onlcr tab3
>>> echo echoe echok echoctl echoke iexten

>> On FreeBSD:

>
> I assume the current code (using `stty size`) works on FreeBSD. Does it
> not?
>

It does. I was aiming at something that would work everywhere.

--
Alex

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need pixie dust for building Python 2.4 curses module on Solaris 8 skip@pobox.com Python 3 06-07-2006 07:28 PM
Still problem with PIX and Solaris-Please help Rob Cisco 2 03-22-2005 09:32 AM
Help with Install of Xerces-c 2.4.0 for Solaris Jim Phelps XML 0 09-17-2004 03:10 PM
Reading ENV vars in Solaris - Indirectly - help! Wells Java 5 05-17-2004 11:23 AM
need help: to switch from software router on Solaris to Cisco 4000-M Kay Cisco 0 07-13-2003 04:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57