/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: John Arbash Meinel
  • Date: 2006-06-17 00:49:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1795.
  • Revision ID: john@arbash-meinel.com-20060617004934-7eb765919f2a4de5
Push should only save the location if it can actually connect (doesn't need to succeed)

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
try:
 
11
   import ctypes
 
12
except ImportError:
 
13
   ctypes = None
 
14
 
 
15
 
 
16
WIN32_STDIN_HANDLE = -10
 
17
WIN32_STDOUT_HANDLE = -11
 
18
WIN32_STDERR_HANDLE = -12
 
19
 
 
20
 
 
21
def get_console_size(defaultx=80, defaulty=25):
 
22
   """ Return size of current console.
 
23
 
 
24
   This function try to determine actual size of current working
 
25
   console window and return tuple (sizex, sizey) if success,
 
26
   or default size (defaultx, defaulty) otherwise.
 
27
 
 
28
   Dependencies: ctypes should be installed.
 
29
   """
 
30
   if ctypes is None:
 
31
       # no ctypes is found
 
32
       return (defaultx, defaulty)
 
33
 
 
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)
 
37
   csbi = ctypes.create_string_buffer(22)
 
38
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
 
39
 
 
40
   if res:
 
41
       (bufx, bufy, curx, cury, wattr,
 
42
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
 
43
       sizex = right - left + 1
 
44
       sizey = bottom - top + 1
 
45
       return (sizex, sizey)
 
46
   else:
 
47
       return (defaultx, defaulty)