Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 11011:648130161e4d
Merge with crew-stable
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Mon, 26 Apr 2010 22:42:46 +0200 |
parents | cd21bf199d17 18e81d42ee5c |
children | 4d8db9676171 |
comparison
equal
deleted
inserted
replaced
11009:4d3288197717 | 11011:648130161e4d |
---|---|
1250 | 1250 |
1251 def uirepr(s): | 1251 def uirepr(s): |
1252 # Avoid double backslash in Windows path repr() | 1252 # Avoid double backslash in Windows path repr() |
1253 return repr(s).replace('\\\\', '\\') | 1253 return repr(s).replace('\\\\', '\\') |
1254 | 1254 |
1255 def termwidth(): | |
1256 if 'COLUMNS' in os.environ: | |
1257 try: | |
1258 return int(os.environ['COLUMNS']) | |
1259 except ValueError: | |
1260 pass | |
1261 try: | |
1262 import termios, array, fcntl | |
1263 for dev in (sys.stderr, sys.stdout, sys.stdin): | |
1264 try: | |
1265 try: | |
1266 fd = dev.fileno() | |
1267 except AttributeError: | |
1268 continue | |
1269 if not os.isatty(fd): | |
1270 continue | |
1271 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8) | |
1272 return array.array('h', arri)[1] | |
1273 except ValueError: | |
1274 pass | |
1275 except IOError, e: | |
1276 if e[0] == errno.EINVAL: | |
1277 pass | |
1278 else: | |
1279 raise | |
1280 except ImportError: | |
1281 pass | |
1282 return 80 | |
1283 | |
1284 def wrap(line, hangindent, width=None): | 1255 def wrap(line, hangindent, width=None): |
1285 if width is None: | 1256 if width is None: |
1286 width = termwidth() - 2 | 1257 width = termwidth() - 2 |
1287 if width <= hangindent: | 1258 if width <= hangindent: |
1288 # adjust for weird terminal size | 1259 # adjust for weird terminal size |
1362 def all(iterable): | 1333 def all(iterable): |
1363 for i in iterable: | 1334 for i in iterable: |
1364 if not i: | 1335 if not i: |
1365 return False | 1336 return False |
1366 return True | 1337 return True |
1338 | |
1339 def termwidth(): | |
1340 if 'COLUMNS' in os.environ: | |
1341 try: | |
1342 return int(os.environ['COLUMNS']) | |
1343 except ValueError: | |
1344 pass | |
1345 return termwidth_() |