~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32console.py

  • Committer: Martin Pool
  • Date: 2006-05-09 07:16:38 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: mbp@sourcefrog.net-20060509071638-c6cb81c352612d82
(win32) Detect terminal width using GetConsoleScreenBufferInfo (Alexander)

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   ctypes = None
14
14
 
15
15
 
 
16
WIN32_STDIN_HANDLE = -10
 
17
WIN32_STDOUT_HANDLE = -11
 
18
WIN32_STDERR_HANDLE = -12
 
19
 
 
20
 
16
21
def get_console_size(defaultx=80, defaulty=25):
17
22
   """ Return size of current console.
18
23
 
26
31
       # no ctypes is found
27
32
       return (defaultx, defaulty)
28
33
 
29
 
   h = ctypes.windll.kernel32.GetStdHandle(-11)
 
34
   # To avoid problem with redirecting output via pipe
 
35
   # need to use stderr instead of stdout
 
36
   h = ctypes.windll.kernel32.GetStdHandle(WIN32_STDERR_HANDLE)
30
37
   csbi = ctypes.create_string_buffer(22)
31
38
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
32
39