Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like there are some problems with that code, Johannes:</p> <ul> <li><code>getTerminalSize</code> needs to <code>import os</code></li> <li>what is <code>env</code>? looks like <code>os.environ</code>.</li> </ul> <p>Also, why switch <code>lines</code> and <code>cols</code> before returning? If <code>TIOCGWINSZ</code> and <code>stty</code> both say <code>lines</code> then <code>cols</code>, I say leave it that way. This confused me for a good 10 minutes before I noticed the inconsistency.</p> <p>Sridhar, I didn't get that error when I piped output. I'm pretty sure it's being caught properly in the try-except.</p> <p>pascal, <code>"HHHH"</code> doesn't work on my machine, but <code>"hh"</code> does. I had trouble finding documentation for that function. It looks like it's platform dependent.</p> <p>chochem, incorporated.</p> <p>Here's my version:</p> <pre><code>def getTerminalSize(): """ returns (lines:int, cols:int) """ import os, struct def ioctl_GWINSZ(fd): import fcntl, termios return struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234")) # try stdin, stdout, stderr for fd in (0, 1, 2): try: return ioctl_GWINSZ(fd) except: pass # try os.ctermid() try: fd = os.open(os.ctermid(), os.O_RDONLY) try: return ioctl_GWINSZ(fd) finally: os.close(fd) except: pass # try `stty size` try: return tuple(int(x) for x in os.popen("stty size", "r").read().split()) except: pass # try environment variables try: return tuple(int(os.getenv(var)) for var in ("LINES", "COLUMNS")) except: pass # i give up. return default. return (25, 80) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload