/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

 * Various microoptimisations to knit and gzip - reducing function call 
   counts in inner loops, reducing double-handling of data, increasing
   knit header parsing performance, removing 'list.index' calls
   completely etc.
 * changes the data format of knits to remove an extraneous \n in the 
   compressed content data, which lets it be trivially pulled into 
   memory in a single 'readlines()' call.
 * changes the knit repository to use unannotated knits for inventory,
   revisions, and signatures. Also turns off delta-compression for
   revisions and signatures.

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