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