mercurial/util.py
changeset 7547 4949729ee9ee
parent 7537 9e186bda013d
child 7559 016a7319e76b
equal deleted inserted replaced
7546:c7f48414f3ad 7547:4949729ee9ee
  1983     return path
  1983     return path
  1984 
  1984 
  1985 def uirepr(s):
  1985 def uirepr(s):
  1986     # Avoid double backslash in Windows path repr()
  1986     # Avoid double backslash in Windows path repr()
  1987     return repr(s).replace('\\\\', '\\')
  1987     return repr(s).replace('\\\\', '\\')
       
  1988 
       
  1989 def termwidth():
       
  1990     if 'COLUMNS' in os.environ:
       
  1991         try:
       
  1992             return int(os.environ['COLUMNS'])
       
  1993         except ValueError:
       
  1994             pass
       
  1995     try:
       
  1996         import termios, array, fcntl
       
  1997         for dev in (sys.stdout, sys.stdin):
       
  1998             try:
       
  1999                 fd = dev.fileno()
       
  2000                 if not os.isatty(fd):
       
  2001                     continue
       
  2002                 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
       
  2003                 return array.array('h', arri)[1]
       
  2004             except ValueError:
       
  2005                 pass
       
  2006     except ImportError:
       
  2007         pass
       
  2008     return 80