##// END OF EJS Templates
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara -
r14515:76f295ea default
parent child Browse files
Show More
@@ -60,7 +60,7 b' from mercurial.i18n import _'
60 60 def _runpager(p):
61 61 if not hasattr(os, 'fork'):
62 62 sys.stdout = util.popen(p, 'wb')
63 if sys.stderr.isatty():
63 if util.isatty(sys.stderr):
64 64 sys.stderr = sys.stdout
65 65 return
66 66 fdin, fdout = os.pipe()
@@ -68,7 +68,7 b' def _runpager(p):'
68 68 if pid == 0:
69 69 os.close(fdin)
70 70 os.dup2(fdout, sys.stdout.fileno())
71 if sys.stderr.isatty():
71 if util.isatty(sys.stderr):
72 72 os.dup2(fdout, sys.stderr.fileno())
73 73 os.close(fdout)
74 74 return
@@ -86,12 +86,13 b' def _runpager(p):'
86 86 raise
87 87
88 88 def uisetup(ui):
89 if ui.plain():
89 if ui.plain() or '--debugger' in sys.argv or not util.isatty(sys.stdout):
90 90 return
91 91
92 92 def pagecmd(orig, ui, options, cmd, cmdfunc):
93 93 p = ui.config("pager", "pager", os.environ.get("PAGER"))
94 if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
94
95 if p:
95 96 attend = ui.configlist('pager', 'attend', attended)
96 97 auto = options['pager'] == 'auto'
97 98 always = util.parsebool(options['pager'])
@@ -46,14 +46,14 b' characters.'
46 46 import sys
47 47 import time
48 48
49 from mercurial import util
49 50 from mercurial.i18n import _
50 51
51 52 def spacejoin(*args):
52 53 return ' '.join(s for s in args if s)
53 54
54 55 def shouldprint(ui):
55 return (getattr(sys.stderr, 'isatty', None) and
56 (sys.stderr.isatty() or ui.configbool('progress', 'assume-tty')))
56 return (util.isatty(sys.stderr) or ui.configbool('progress', 'assume-tty'))
57 57
58 58 def fmtremaining(seconds):
59 59 if seconds < 60:
@@ -473,12 +473,9 b' class ui(object):'
473 473 '''
474 474 i = self.configbool("ui", "interactive", None)
475 475 if i is None:
476 try:
477 return sys.stdin.isatty()
478 except AttributeError:
479 # some environments replace stdin without implementing isatty
480 # usually those are non-interactive
481 return False
476 # some environments replace stdin without implementing isatty
477 # usually those are non-interactive
478 return util.isatty(sys.stdin)
482 479
483 480 return i
484 481
@@ -514,17 +511,14 b' class ui(object):'
514 511
515 512 i = self.configbool("ui", "formatted", None)
516 513 if i is None:
517 try:
518 return sys.stdout.isatty()
519 except AttributeError:
520 # some environments replace stdout without implementing isatty
521 # usually those are non-interactive
522 return False
514 # some environments replace stdout without implementing isatty
515 # usually those are non-interactive
516 return util.isatty(sys.stdout)
523 517
524 518 return i
525 519
526 520 def _readline(self, prompt=''):
527 if sys.stdin.isatty():
521 if util.isatty(sys.stdin):
528 522 try:
529 523 # magically add command line editing support, where
530 524 # available
@@ -1591,3 +1591,9 b' def removeauth(u):'
1591 1591 u = url(u)
1592 1592 u.user = u.passwd = None
1593 1593 return str(u)
1594
1595 def isatty(fd):
1596 try:
1597 return fd.isatty()
1598 except AttributeError:
1599 return False
General Comments 0
You need to be logged in to leave comments. Login now