Commit 5489ce99 by willmcgugan

Added detection of Windows console size

parent 41f9600f
...@@ -10,7 +10,35 @@ import platform ...@@ -10,7 +10,35 @@ import platform
from collections import defaultdict from collections import defaultdict
import re import re
if platform.system() == 'Linux' : if platform.system() == 'Windows':
def getTerminalSize():
try:
## {{{ http://code.activestate.com/recipes/440694/ (r3)
from ctypes import windll, create_string_buffer
# stdin handle is -10
# stdout handle is -11
# stderr handle is -12
h = windll.kernel32.GetStdHandle(-12)
csbi = create_string_buffer(22)
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
if res:
import struct
(bufx, bufy, curx, cury, wattr,
left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
sizex = right - left + 1
sizey = bottom - top + 1
else:
sizex, sizey = 80, 25 # can't determine actual size - return default values
return sizex, sizey
except:
return 80, 25
else:
def getTerminalSize(): def getTerminalSize():
def ioctl_GWINSZ(fd): def ioctl_GWINSZ(fd):
try: try:
...@@ -34,9 +62,7 @@ if platform.system() == 'Linux' : ...@@ -34,9 +62,7 @@ if platform.system() == 'Linux' :
except: except:
cr = (25, 80) cr = (25, 80)
return int(cr[1]), int(cr[0]) return int(cr[1]), int(cr[0])
else:
def getTerminalSize():
return 80, 50
def _unicode(text): def _unicode(text):
if not isinstance(text, unicode): if not isinstance(text, unicode):
......
...@@ -4,7 +4,7 @@ fs.mountfs ...@@ -4,7 +4,7 @@ fs.mountfs
Contains MountFS class which is a virtual filesystem which can have other filesystems linked as branched directories. Contains MountFS class which is a virtual filesystem which can have other filesystems linked as branched directories.
For example, lets say we have two filesystems containing config files and resource respectively:: For example, lets say we have two filesystems containing config files and resources respectively::
[config_fs] [config_fs]
|-- config.cfg |-- config.cfg
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment