Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ui.py @ 8208:32a2a1e244f1
ui: make interactive a method
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 26 Apr 2009 16:50:44 -0500 |
parents | cce63ef1045b |
children | 6e6ebeb52899 |
line wrap: on
line diff
--- a/mercurial/ui.py Sun Apr 26 16:50:44 2009 -0500 +++ b/mercurial/ui.py Sun Apr 26 16:50:44 2009 -0500 @@ -16,7 +16,7 @@ def __init__(self, src=None): self._buffers = [] self.quiet = self.verbose = self.debugflag = self._traceback = False - self.interactive = self._reportuntrusted = True + self._reportuntrusted = True self._ocfg = config.config() # overlay self._tcfg = config.config() # trusted self._ucfg = config.config() # untrusted @@ -37,18 +37,6 @@ def copy(self): return ui(self) - _isatty = None - def isatty(self): - if ui._isatty is None: - try: - ui._isatty = sys.stdin.isatty() - except AttributeError: # not a real file object - ui._isatty = False - except IOError: - # access to stdin is unsafe in a WSGI environment - ui._isatty = False - return ui._isatty - def _is_trusted(self, fp, f): st = util.fstat(fp) if util.isowner(fp, st): @@ -112,7 +100,6 @@ if self.verbose and self.quiet: self.quiet = self.verbose = False self._reportuntrusted = self.configbool("ui", "report_untrusted", True) - self.interactive = self.configbool("ui", "interactive", self.isatty()) self._traceback = self.configbool('ui', 'traceback', False) # update trust information @@ -259,8 +246,11 @@ try: sys.stderr.flush() except: pass + def interactive(self): + return self.configbool("ui", "interactive") or sys.stdin.isatty() + def _readline(self, prompt=''): - if self.isatty(): + if sys.stdin.isatty(): try: # magically add command line editing support, where # available @@ -282,7 +272,7 @@ If not interactive -- the default is returned """ - if not self.interactive: + if not self.interactive(): self.note(msg, ' ', default, "\n") return default while True: @@ -298,7 +288,7 @@ raise util.Abort(_('response expected')) def getpass(self, prompt=None, default=None): - if not self.interactive: return default + if not self.interactive(): return default try: return getpass.getpass(prompt or _('password: ')) except EOFError: