Show More
@@ -1,95 +1,95 b'' | |||
|
1 | 1 | import array |
|
2 | 2 | import errno |
|
3 | 3 | import fcntl |
|
4 | 4 | import os |
|
5 | 5 | import sys |
|
6 | 6 | |
|
7 | 7 | from .pycompat import getattr |
|
8 | 8 | from . import ( |
|
9 | 9 | encoding, |
|
10 | 10 | pycompat, |
|
11 | 11 | util, |
|
12 | 12 | ) |
|
13 | 13 | |
|
14 | 14 | # BSD 'more' escapes ANSI color sequences by default. This can be disabled by |
|
15 | 15 | # $MORE variable, but there's no compatible option with Linux 'more'. Given |
|
16 | 16 | # OS X is widely used and most modern Unix systems would have 'less', setting |
|
17 | 17 | # 'less' as the default seems reasonable. |
|
18 | 18 | fallbackpager = b'less' |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | def _rcfiles(path): |
|
22 | 22 | rcs = [os.path.join(path, b'hgrc')] |
|
23 | 23 | rcdir = os.path.join(path, b'hgrc.d') |
|
24 | 24 | try: |
|
25 | 25 | rcs.extend( |
|
26 | 26 | [ |
|
27 | 27 | os.path.join(rcdir, f) |
|
28 | 28 | for f, kind in sorted(util.listdir(rcdir)) |
|
29 | 29 | if f.endswith(b".rc") |
|
30 | 30 | ] |
|
31 | 31 | ) |
|
32 | 32 | except OSError: |
|
33 | 33 | pass |
|
34 | 34 | return rcs |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | def systemrcpath(): |
|
38 | 38 | path = [] |
|
39 | 39 | if pycompat.sysplatform == b'plan9': |
|
40 | 40 | root = b'lib/mercurial' |
|
41 | 41 | else: |
|
42 | 42 | root = b'etc/mercurial' |
|
43 | 43 | # old mod_python does not set sys.argv |
|
44 | 44 | if len(getattr(sys, 'argv', [])) > 0: |
|
45 | 45 | p = os.path.dirname(os.path.dirname(pycompat.sysargv[0])) |
|
46 | 46 | if p != b'/': |
|
47 | 47 | path.extend(_rcfiles(os.path.join(p, root))) |
|
48 | 48 | path.extend(_rcfiles(b'/' + root)) |
|
49 | 49 | return path |
|
50 | 50 | |
|
51 | 51 | |
|
52 | 52 | def userrcpath(): |
|
53 | 53 | if pycompat.sysplatform == b'plan9': |
|
54 | 54 | return [encoding.environ[b'home'] + b'/lib/hgrc'] |
|
55 | 55 | elif pycompat.isdarwin: |
|
56 | 56 | return [os.path.expanduser(b'~/.hgrc')] |
|
57 | 57 | else: |
|
58 | 58 | confighome = encoding.environ.get(b'XDG_CONFIG_HOME') |
|
59 | 59 | if confighome is None or not os.path.isabs(confighome): |
|
60 | 60 | confighome = os.path.expanduser(b'~/.config') |
|
61 | 61 | |
|
62 | 62 | return [ |
|
63 | 63 | os.path.expanduser(b'~/.hgrc'), |
|
64 | 64 | os.path.join(confighome, b'hg', b'hgrc'), |
|
65 | 65 | ] |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | def termsize(ui): |
|
69 | 69 | try: |
|
70 | 70 | import termios |
|
71 | 71 | |
|
72 | 72 | TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449) |
|
73 | 73 | except (AttributeError, ImportError): |
|
74 | 74 | return 80, 24 |
|
75 | 75 | |
|
76 | 76 | for dev in (ui.ferr, ui.fout, ui.fin): |
|
77 | 77 | try: |
|
78 | 78 | try: |
|
79 | 79 | fd = dev.fileno() |
|
80 | 80 | except AttributeError: |
|
81 | 81 | continue |
|
82 | 82 | if not os.isatty(fd): |
|
83 | 83 | continue |
|
84 | 84 | arri = fcntl.ioctl(fd, TIOCGWINSZ, b'\0' * 8) |
|
85 | 85 | height, width = array.array('h', arri)[:2] |
|
86 | 86 | if width > 0 and height > 0: |
|
87 | 87 | return width, height |
|
88 | 88 | except ValueError: |
|
89 | 89 | pass |
|
90 | 90 | except IOError as e: |
|
91 | if e[0] == errno.EINVAL: # pytype: disable=unsupported-operands | |
|
91 | if e.errno == errno.EINVAL: | |
|
92 | 92 | pass |
|
93 | 93 | else: |
|
94 | 94 | raise |
|
95 | 95 | return 80, 24 |
General Comments 0
You need to be logged in to leave comments.
Login now