mercurial/posix.py
branchstable
changeset 11010 18e81d42ee5c
parent 10264 d6512b3e9ac0
child 11011 648130161e4d
--- a/mercurial/posix.py	Tue Apr 27 00:44:06 2010 +0530
+++ b/mercurial/posix.py	Mon Apr 26 22:30:40 2010 +0200
@@ -264,3 +264,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