def get_console_width():
if os.name == '<STR_LIT>':<EOL><INDENT>STD_INPUT_HANDLE = -<NUM_LIT:10><EOL>STD_OUTPUT_HANDLE = -<NUM_LIT:11><EOL>STD_ERROR_HANDLE = -<NUM_LIT:12><EOL>from ctypes import windll, Structure, byref<EOL>try:<EOL><INDENT>from ctypes.wintypes import SHORT, WORD, DWORD<EOL><DEDENT>except ImportError:<EOL><INDENT>from ctypes import (<EOL>c_short as SHORT, c_ushort as WORD, c_ulong as DWORD)<EOL><DEDENT>console_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)<EOL>class COORD(Structure):<EOL><INDENT>_fields_ = [("<STR_LIT:X>", SHORT), ("<STR_LIT:Y>", SHORT)]<EOL><DEDENT>class SMALL_RECT(Structure):<EOL><INDENT>_fields_ = [("<STR_LIT>", SHORT), ("<STR_LIT>", SHORT),<EOL>("<STR_LIT>", SHORT), ("<STR_LIT>", SHORT)]<EOL><DEDENT>class CONSOLE_SCREEN_BUFFER_INFO(Structure):<EOL><INDENT>_fields_ = [("<STR_LIT>", COORD),<EOL>("<STR_LIT>", COORD),<EOL>("<STR_LIT>", WORD),<EOL>("<STR_LIT>", SMALL_RECT),<EOL>("<STR_LIT>", DWORD)]<EOL><DEDENT>sbi = CONSOLE_SCREEN_BUFFER_INFO()<EOL>ret = windll.kernel32.GetConsoleScreenBufferInfo(<EOL>console_handle, byref(sbi))<EOL>if ret == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>return sbi.srWindow.Right + <NUM_LIT:1><EOL><DEDENT>elif os.name == '<STR_LIT>':<EOL><INDENT>from fcntl import ioctl<EOL>from termios import TIOCGWINSZ<EOL>from array import array<EOL>winsize = array("<STR_LIT:H>", [<NUM_LIT:0>] * <NUM_LIT:4>)<EOL>try:<EOL><INDENT>ioctl(sys.stdout.fileno(), TIOCGWINSZ, winsize)<EOL><DEDENT>except IOError:<EOL><INDENT>pass<EOL><DEDENT>return (winsize[<NUM_LIT:1>], winsize[<NUM_LIT:0>])[<NUM_LIT:0>]<EOL><DEDENT>return <NUM_LIT><EOL>
Return width of available window area. Autodetection works for
       Windows and POSIX platforms. Returns 80 for others

       Code from http://bitbucket.org/techtonik/python-pager