Permalink
Browse files

Added a library for getting console side. Will incorporate into JIRA …

…script if it works well on Linux.
  • Loading branch information...
1 parent deac628 commit 5feaf5a16dc09c1aa79c18f2f6508e399c18892a @sean-m committed Feb 5, 2013
Showing with 35 additions and 0 deletions.
  1. +35 −0 console.py
View
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+def getTerminalSize():
+ import os
+ env = os.environ
+ def ioctl_GWINSZ(fd):
+ try:
+ import fcntl, termios, struct, os
+ cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
+ '1234'))
+ except:
+ return
+ return cr
+ cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
+ if not cr:
+ try:
+ fd = os.open(os.ctermid(), os.O_RDONLY)
+ cr = ioctl_GWINSZ(fd)
+ os.close(fd)
+ except:
+ pass
+ if not cr:
+ cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
+
+ ### Use get(key[, default]) instead of a try/catch
+ #try:
+ # cr = (env['LINES'], env['COLUMNS'])
+ #except:
+ # cr = (25, 80)
+ return int(cr[1]), int(cr[0])
+
+
+
+if __name__ == '__main__':
+ print(getTerminalSize())

0 comments on commit 5feaf5a

Please sign in to comment.