/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: Alexander Belchenko
  • Date: 2006-08-17 12:14:57 UTC
  • mto: (1711.2.128 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1939.
  • Revision ID: bialix@ukr.net-20060817121457-44e8499df346c8bb
New target to produce html docs to upload on server

- 'make htmldocs' translate docs to html 
  and copy documentation to folder html_docs
  (can be tuned by variable HTMLDIR inside Makefile)
- 'make clean-docs' remove generated html files
- provide consistency in make targets
- added dependencies for bzr_man.txt

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)