getting terminal display size?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jeff

    #1

    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?

  • Grant Edwards

    #2
    Re: getting terminal display size?

    On 2007-02-26, jeff <jeffrey.aylesw orth@gmail.comw rote:
    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("HH HH", 0, 0, 0, 0)
    fd_stdout = sys.stdout.file no()
    x = fcntl.ioctl(fd_ stdout, termios.TIOCGWI NSZ, s)
    print '(rows, cols, x pixels, y pixels) =',
    print struct.unpack(" HHHH", x)



    --
    Grant Edwards
    grante@visi.com

    Comment

    • Grant Edwards

      #3
      Re: getting terminal display size?

      On 2007-02-26, Grant Edwards <grante@visi.co mwrote:
      On 2007-02-26, jeff <jeffrey.aylesw orth@gmail.comw rote:
      >
      >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("HH HH", 0, 0, 0, 0)
      fd_stdout = sys.stdout.file no()
      x = fcntl.ioctl(fd_ stdout, termios.TIOCGWI NSZ, 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.

      --

      Comment

      • jeff

        #4
        Re: getting terminal display size?

        I don't really understand any of that; can you right me a function
        that'll return the size as a tuple?

        Comment

        • Joshua J. Kugler

          #5
          Re: getting terminal display size?

          jeff wrote:
          I don't really understand any of that; can you right me a function
          that'll return the size as a tuple?
          Did you even *try* his code? I ran this:

          import termios, fcntl, struct, sys

          s = struct.pack("HH HH", 0, 0, 0, 0)
          fd_stdout = sys.stdout.file no()
          x = fcntl.ioctl(fd_ stdout, termios.TIOCGWI NSZ, s)
          print '(rows, cols, x pixels, y pixels) =',
          print struct.unpack(" HHHH", x)

          And got this result:

          (36, 96, 0, 0)

          Looks like a tuple to me. return 'return' instead of 'print' the result.
          We don't mind helping, but it's nice to know that the user has made some
          attempt to understand what is going on before asking for free work to be
          done.

          j



          --
          Joshua Kugler
          Lead System Admin -- Senior Programmer

          PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

          --
          Posted via a free Usenet account from http://www.teranews.com

          Comment

          • Grant Edwards

            #6
            Re: getting terminal display size?

            On 2007-02-27, jeff <jeffrey.aylesw orth@gmail.comw rote:
            I don't really understand any of that; can you right me a function
            that'll return the size as a tuple?
            What do you think I posted?

            --
            Grant Edwards grante Yow! I selected E5... but
            at I didn't hear "Sam the Sham
            visi.com and the Pharoahs"!

            Comment

            • jeff

              #7
              Re: getting terminal display size?

              On Feb 26, 8:01 pm, Grant Edwards <gra...@visi.co mwrote:
              On 2007-02-27, jeff <jeffrey.aylesw o...@gmail.comw rote:
              >
              I don't really understand any of that; can you right me a function
              that'll return the size as a tuple?
              >
              What do you think I posted?
              >
              --
              Grant Edwards grante Yow! I selected E5... but
              at I didn't hear "Sam the Sham
              visi.com and the Pharoahs"!
              nevermind, I figured it outr, it just looked confusing

              Comment

              Working...