mercurial/posix.py
changeset 11011 648130161e4d
parent 10757 ab3782458827
parent 11010 18e81d42ee5c
child 11138 99eee847beaa
--- a/mercurial/posix.py	Mon Apr 26 21:35:09 2010 +0200
+++ b/mercurial/posix.py	Mon Apr 26 22:42:46 2010 +0200
@@ -265,3 +265,27 @@
 
 def gethgcmd():
     return sys.argv[:1]
+
+def termwidth_():
+    try:
+        import termios, array, fcntl
+        for dev in (sys.stderr, sys.stdout, sys.stdin):
+            try:
+                try:
+                    fd = dev.fileno()
+                except AttributeError:
+                    continue
+                if not os.isatty(fd):
+                    continue
+                arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
+                return array.array('h', arri)[1]
+            except ValueError:
+                pass
+            except IOError, e:
+                if e[0] == errno.EINVAL:
+                    pass
+                else:
+                    raise
+    except ImportError:
+        pass
+    return 80