Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

getting terminal display size?


I looked around a lot on the internet and couldn't find out how to do
this, how do I get the sizer (in rows and columns) of the view?
On 25 Feb 2007 16:53:17 -0800, jeff <jeffrey.ayleswo@gmail.com> wrote:

>I looked around a lot on the internet and couldn't find out how to do
>this, how do I get the sizer (in rows and columns) of the view?

Assuming you're talking about something vaguely *NIXy, you want something
like what's being done here:

http://twistedmatrix.com/trac/browser/trunk/twisted/conch/scripts/con...

Jean-Paul

On 2007-02-26, jeff <jeffrey.ayleswo@gmail.com> wrote:

> I looked around a lot on the internet and couldn't find out how to do
> this, how do I get the sizer (in rows and columns) of the view?

You use the TIOCGWINSZ ioctl() call on the tty device in question.

  import termios, fcntl, struct, sys

  s = struct.pack("HHHH", 0, 0, 0, 0)
  fd_stdout = sys.stdout.fileno()
  x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
  print '(rows, cols, x pixels, y pixels) =',
  print struct.unpack("HHHH", x)

--
Grant Edwards
gra@visi.com

On 2007-02-26, Grant Edwards <gra@visi.com> wrote:

> On 2007-02-26, jeff <jeffrey.ayleswo@gmail.com> wrote:

>> I looked around a lot on the internet and couldn't find out how to do
>> this, how do I get the sizer (in rows and columns) of the view?

> You use the TIOCGWINSZ ioctl() call on the tty device in question.

>   import termios, fcntl, struct, sys

>   s = struct.pack("HHHH", 0, 0, 0, 0)
>   fd_stdout = sys.stdout.fileno()
>   x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
>   print '(rows, cols, x pixels, y pixels) =',
>   print struct.unpack("HHHH", x)

You may also want to handle the WINCH signal so that you know
when the window size has been changed.

--

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc