comparison mercurial/win32.py @ 11012:81631f0cf13b

win32: detect console width on Windows Original version by anatoly techtonik <techtonik@gmail.com> Following advices from similar bzr code.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 25 Apr 2010 18:27:12 +0200
parents 07bd7608a0ea
children 8c377f2feee1
comparison
equal deleted inserted replaced
11011:648130161e4d 11012:81631f0cf13b
14 """ 14 """
15 15
16 import win32api 16 import win32api
17 17
18 import errno, os, sys, pywintypes, win32con, win32file, win32process 18 import errno, os, sys, pywintypes, win32con, win32file, win32process
19 import winerror, win32gui 19 import winerror, win32gui, win32console
20 import osutil, encoding 20 import osutil, encoding
21 from win32com.shell import shell, shellcon 21 from win32com.shell import shell, shellcon
22 22
23 def os_link(src, dst): 23 def os_link(src, dst):
24 try: 24 try:
187 if pid == wpid: 187 if pid == wpid:
188 win32gui.ShowWindow(hwnd, win32con.SW_HIDE) 188 win32gui.ShowWindow(hwnd, win32con.SW_HIDE)
189 189
190 pid = win32process.GetCurrentProcessId() 190 pid = win32process.GetCurrentProcessId()
191 win32gui.EnumWindows(callback, pid) 191 win32gui.EnumWindows(callback, pid)
192
193 def termwidth_():
194 try:
195 # Query stderr to avoid problems with redirections
196 screenbuf = win32console.GetStdHandle(win32console.STD_ERROR_HANDLE)
197 try:
198 window = screenbuf.GetConsoleScreenBufferInfo()['Window']
199 width = window.Right - window.Left
200 return width
201 finally:
202 screenbuf.Detach()
203 except pywintypes.error:
204 return 79