Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/scmposix.py @ 30327:365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
It appears crecord.py has its own termsize() function. I want to get rid of it.
The fallback height is chosen from the default of cmd.exe on Windows, and
VT100 on Unix.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 23:09:05 +0900 |
parents | 1ad1c5017043 |
children | 5b0baa9f3362 |
comparison
equal
deleted
inserted
replaced
30326:392633d7860e | 30327:365812902904 |
---|---|
40 if sys.platform == 'plan9': | 40 if sys.platform == 'plan9': |
41 return [encoding.environ['home'] + '/lib/hgrc'] | 41 return [encoding.environ['home'] + '/lib/hgrc'] |
42 else: | 42 else: |
43 return [os.path.expanduser('~/.hgrc')] | 43 return [os.path.expanduser('~/.hgrc')] |
44 | 44 |
45 def termwidth(ui): | 45 def termsize(ui): |
46 try: | 46 try: |
47 import termios | 47 import termios |
48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) | 48 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) |
49 except (AttributeError, ImportError): | 49 except (AttributeError, ImportError): |
50 return 80 | 50 return 80, 24 |
51 | 51 |
52 for dev in (ui.ferr, ui.fout, ui.fin): | 52 for dev in (ui.ferr, ui.fout, ui.fin): |
53 try: | 53 try: |
54 try: | 54 try: |
55 fd = dev.fileno() | 55 fd = dev.fileno() |
56 except AttributeError: | 56 except AttributeError: |
57 continue | 57 continue |
58 if not os.isatty(fd): | 58 if not os.isatty(fd): |
59 continue | 59 continue |
60 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8) | 60 arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8) |
61 width = array.array('h', arri)[1] | 61 height, width = array.array('h', arri)[:2] |
62 if width > 0: | 62 if width > 0 and height > 0: |
63 return width | 63 return width, height |
64 except ValueError: | 64 except ValueError: |
65 pass | 65 pass |
66 except IOError as e: | 66 except IOError as e: |
67 if e[0] == errno.EINVAL: | 67 if e[0] == errno.EINVAL: |
68 pass | 68 pass |
69 else: | 69 else: |
70 raise | 70 raise |
71 return 80 | 71 return 80, 24 |