mercurial/scmposix.py
changeset 30322 4b1af1c867fa
parent 30290 c90a05124fae
child 30323 5c379b1f56c7
equal deleted inserted replaced
30321:d500ddae7494 30322:4b1af1c867fa
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
       
     3 import errno
       
     4 import fcntl
     3 import os
     5 import os
     4 import sys
     6 import sys
     5 
     7 
     6 from . import (
     8 from . import (
     7     encoding,
     9     encoding,
    36 def userrcpath():
    38 def userrcpath():
    37     if sys.platform == 'plan9':
    39     if sys.platform == 'plan9':
    38         return [encoding.environ['home'] + '/lib/hgrc']
    40         return [encoding.environ['home'] + '/lib/hgrc']
    39     else:
    41     else:
    40         return [os.path.expanduser('~/.hgrc')]
    42         return [os.path.expanduser('~/.hgrc')]
       
    43 
       
    44 def termwidth():
       
    45     try:
       
    46         import array
       
    47         import termios
       
    48         for dev in (sys.stderr, sys.stdout, sys.stdin):
       
    49             try:
       
    50                 try:
       
    51                     fd = dev.fileno()
       
    52                 except AttributeError:
       
    53                     continue
       
    54                 if not os.isatty(fd):
       
    55                     continue
       
    56                 try:
       
    57                     arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
       
    58                     width = array.array('h', arri)[1]
       
    59                     if width > 0:
       
    60                         return width
       
    61                 except AttributeError:
       
    62                     pass
       
    63             except ValueError:
       
    64                 pass
       
    65             except IOError as e:
       
    66                 if e[0] == errno.EINVAL:
       
    67                     pass
       
    68                 else:
       
    69                     raise
       
    70     except ImportError:
       
    71         pass
       
    72     return 80