/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: Robert Collins
  • Date: 2006-09-10 23:42:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2000.
  • Revision ID: robertc@robertcollins.net-20060910234217-0ae24d8e666d60d6
All WorkingTree methods which write to the tree, but not to the branch
have been converted to use ``needs_tree_write_lock`` rather than 
``needs_write_lock``. Also converted is the revert, conflicts and tree
transform modules. This provides a modest performance improvement on 
metadir style trees, due to the reduce lock-acquisition, and a more
significant performance improvement on lightweight checkouts from 
remote branches, where trivial operations used to pay a significant 
penalty. It also provides the basis for allowing readonly checkouts.
(Robert Collins)

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)