comparison mercurial/posix.py @ 11010:18e81d42ee5c stable

util: fix default termwidth() under Windows sys.stdout.write('-'*80 + '\n') or sys.stdout.write('-'*80 + '\r') do not work on Windows as they do on unix. On a 80 columns Windows console, the extra CR or LF are interpreted as if belonging to the next line, so the first command displays 2 lines (only one on unix) and the second one leave the line visible and move back to the following line. To avoid this, we sacrifice one column under Windows.
author Patrick Mezard <pmezard@gmail.com>
date Mon, 26 Apr 2010 22:30:40 +0200
parents d6512b3e9ac0
children 648130161e4d
comparison
equal deleted inserted replaced
11007:a0102da324ab 11010:18e81d42ee5c
262 return os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), 262 return os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0),
263 args[0], args) 263 args[0], args)
264 264
265 def gethgcmd(): 265 def gethgcmd():
266 return sys.argv[:1] 266 return sys.argv[:1]
267
268 def termwidth_():
269 try:
270 import termios, array, fcntl
271 for dev in (sys.stderr, sys.stdout, sys.stdin):
272 try:
273 try:
274 fd = dev.fileno()
275 except AttributeError:
276 continue
277 if not os.isatty(fd):
278 continue
279 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
280 return array.array('h', arri)[1]
281 except ValueError:
282 pass
283 except IOError, e:
284 if e[0] == errno.EINVAL:
285 pass
286 else:
287 raise
288 except ImportError:
289 pass
290 return 80