~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32console.py

  • Committer: Robert Collins
  • Date: 2005-11-28 05:13:41 UTC
  • mfrom: (1185.33.54 merge-recovered)
  • Revision ID: robertc@robertcollins.net-20051128051341-059936f2f29a12c8
Merge from Martin. Adjust check to work with HTTP again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
1
 
18
2
"""
19
3
Set of functions to work with console on Windows.
23
7
 
24
8
import struct
25
9
 
26
 
# We can cope without it; use a separate variable to help pyflakes
27
10
try:
28
11
   import ctypes
29
 
   has_ctypes = True
30
12
except ImportError:
31
 
    has_ctypes = False
32
 
 
33
 
 
34
 
WIN32_STDIN_HANDLE = -10
35
 
WIN32_STDOUT_HANDLE = -11
36
 
WIN32_STDERR_HANDLE = -12
 
13
   ctypes = None
37
14
 
38
15
 
39
16
def get_console_size(defaultx=80, defaulty=25):
45
22
 
46
23
   Dependencies: ctypes should be installed.
47
24
   """
48
 
   if not has_ctypes:
 
25
   if ctypes is None:
49
26
       # no ctypes is found
50
27
       return (defaultx, defaulty)
51
28
 
52
 
   # To avoid problem with redirecting output via pipe
53
 
   # need to use stderr instead of stdout
54
 
   h = ctypes.windll.kernel32.GetStdHandle(WIN32_STDERR_HANDLE)
 
29
   h = ctypes.windll.kernel32.GetStdHandle(-11)
55
30
   csbi = ctypes.create_string_buffer(22)
56
31
   res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
57
32