# HG changeset patch # User Patrick Mezard # Date 1272212832 -7200 # Node ID 81631f0cf13b1d289ca9ac004bbd5b63e1384cda # Parent 648130161e4da3c07cd0585a7e97a0df3ceedabb win32: detect console width on Windows Original version by anatoly techtonik Following advices from similar bzr code. diff -r 648130161e4d -r 81631f0cf13b mercurial/win32.py --- a/mercurial/win32.py Mon Apr 26 22:42:46 2010 +0200 +++ b/mercurial/win32.py Sun Apr 25 18:27:12 2010 +0200 @@ -16,7 +16,7 @@ import win32api import errno, os, sys, pywintypes, win32con, win32file, win32process -import winerror, win32gui +import winerror, win32gui, win32console import osutil, encoding from win32com.shell import shell, shellcon @@ -189,3 +189,16 @@ pid = win32process.GetCurrentProcessId() win32gui.EnumWindows(callback, pid) + +def termwidth_(): + try: + # Query stderr to avoid problems with redirections + screenbuf = win32console.GetStdHandle(win32console.STD_ERROR_HANDLE) + try: + window = screenbuf.GetConsoleScreenBufferInfo()['Window'] + width = window.Right - window.Left + return width + finally: + screenbuf.Detach() + except pywintypes.error: + return 79