~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32console.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-29 15:31:52 UTC
  • mfrom: (2052.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060929153152-9a32a9b020e0f74b
Lukáš Lalinský: Windows-speficic smart server transport selftest fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
import struct
9
9
 
 
10
# We can cope without it; use a separate variable to help pyflakes
10
11
try:
11
12
   import ctypes
 
13
   has_ctypes = True
12
14
except ImportError:
13
 
   ctypes = None
 
15
    has_ctypes = False
 
16
 
 
17
 
 
18
WIN32_STDIN_HANDLE = -10
 
19
WIN32_STDOUT_HANDLE = -11
 
20
WIN32_STDERR_HANDLE = -12
14
21
 
15
22
 
16
23
def get_console_size(defaultx=80, defaulty=25):
22
29
 
23
30
   Dependencies: ctypes should be installed.
24
31
   """
25
 
   if ctypes is None:
 
32
   if not has_ctypes:
26
33
       # no ctypes is found
27
34
       return (defaultx, defaulty)
28
35
 
29
 
   h = ctypes.windll.kernel32.GetStdHandle(-11)
 
36
   # To avoid problem with redirecting output via pipe
 
37
   # need to use stderr instead of stdout
 
38
   h = ctypes.windll.kernel32.GetStdHandle(WIN32_STDERR_HANDLE)
30
39
   csbi = ctypes.create_string_buffer(22)
31
40
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
32
41