3
Set of functions to work with console on Windows.
 
 
4
Author: Alexander Belchenko (e-mail: bialix AT ukr.net)
 
 
16
def get_console_size(defaultx=80, defaulty=25):
 
 
17
   """ Return size of current console.
 
 
19
   This function try to determine actual size of current working
 
 
20
   console window and return tuple (sizex, sizey) if success,
 
 
21
   or default size (defaultx, defaulty) otherwise.
 
 
23
   Dependencies: ctypes should be installed.
 
 
27
       return (defaultx, defaulty)
 
 
29
   h = ctypes.windll.kernel32.GetStdHandle(-11)
 
 
30
   csbi = ctypes.create_string_buffer(22)
 
 
31
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
 
 
34
       (bufx, bufy, curx, cury, wattr,
 
 
35
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
 
 
36
       sizex = right - left + 1
 
 
37
       sizey = bottom - top + 1
 
 
40
       return (defaultx, defaulty)