#NEWLINE# def get_terminal_size( defaultx = 80 , defaulty = 25 ) : #NEWLINE# #INDENT# 'Return size of current terminal console.\n\n        This function try to determine actual size of current working\n        console window and return tuple (sizex, sizey) if success,\n        or default size (defaultx, defaulty) otherwise.\n\n        Dependencies: ctypes should be installed.\n\n        Author: Alexander Belchenko (e-mail: bialix AT ukr.net)\n        ' #NEWLINE# try : #NEWLINE# #INDENT# import ctypes #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# return ( defaultx , defaulty ) #NEWLINE# #UNINDENT# h = ctypes . windll . kernel32 . GetStdHandle ( ( - 11 ) ) #NEWLINE# csbi = ctypes . create_string_buffer ( 22 ) #NEWLINE# res = ctypes . windll . kernel32 . GetConsoleScreenBufferInfo ( h , csbi ) #NEWLINE# if res : #NEWLINE# #INDENT# ( bufx , bufy , curx , cury , wattr , left , top , right , bottom , maxx , maxy ) = struct . unpack ( 'hhhhHhhhhhh' , csbi . raw ) #NEWLINE# sizex = ( ( right - left ) + 1 ) #NEWLINE# sizey = ( ( bottom - top ) + 1 ) #NEWLINE# return ( sizex , sizey ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( defaultx , left )