/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32console.py

  • Committer: Martin Pool
  • Date: 2006-07-12 05:22:48 UTC
  • mto: This revision was merged to the branch mainline in revision 1856.
  • Revision ID: mbp@sourcefrog.net-20060712052248-789ab09214cf9fef
      Improvements to hashcache testing:
      
       - moves the functions that depend on the OS state into HashCache
       - removes dead 'FixThisError' (??) from test_hashcache
       - adds new FakeHashCache, which gives the test suite control of
         how the files and clock appear to the hashcache
       - new tests using this which check three key behaviours:
         - new files are not inserted in the cache
         - old files are inserted in the cache and can hit
         - if a file is modified within a short time window, we don't get
           an incorrect cached result

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""
 
3
Set of functions to work with console on Windows.
 
4
Author: Alexander Belchenko (e-mail: bialix AT ukr.net)
 
5
License: Public domain
 
6
"""
 
7
 
 
8
import struct
 
9
 
 
10
# We can cope without it; use a separate variable to help pyflakes
 
11
try:
 
12
   import ctypes
 
13
   has_ctypes = True
 
14
except ImportError:
 
15
    has_ctypes = False
 
16
 
 
17
 
 
18
WIN32_STDIN_HANDLE = -10
 
19
WIN32_STDOUT_HANDLE = -11
 
20
WIN32_STDERR_HANDLE = -12
 
21
 
 
22
 
 
23
def get_console_size(defaultx=80, defaulty=25):
 
24
   """ Return size of current console.
 
25
 
 
26
   This function try to determine actual size of current working
 
27
   console window and return tuple (sizex, sizey) if success,
 
28
   or default size (defaultx, defaulty) otherwise.
 
29
 
 
30
   Dependencies: ctypes should be installed.
 
31
   """
 
32
   if not has_ctypes:
 
33
       # no ctypes is found
 
34
       return (defaultx, defaulty)
 
35
 
 
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)
 
39
   csbi = ctypes.create_string_buffer(22)
 
40
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
 
41
 
 
42
   if res:
 
43
       (bufx, bufy, curx, cury, wattr,
 
44
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
 
45
       sizex = right - left + 1
 
46
       sizey = bottom - top + 1
 
47
       return (sizex, sizey)
 
48
   else:
 
49
       return (defaultx, defaulty)