def _readline(self, prompt=''): if util.isatty(self.fin): try: # magically add command line editing support, where # available import readline # force demandimport to really load the module readline.read_history_file # windows sometimes raises something other than ImportError except Exception: pass # call write() so output goes through subclassed implementation # e.g. color extension on Windows self.write(prompt) # instead of trying to emulate raw_input, swap (self.fin, # self.fout) with (sys.stdin, sys.stdout) oldin = sys.stdin oldout = sys.stdout sys.stdin = self.fin sys.stdout = self.fout line = raw_input(' ') sys.stdin = oldin sys.stdout = oldout # When stdin is in binary mode on Windows, it can cause # raw_input() to emit an extra trailing carriage return if os.linesep == '\r\n' and line and line[-1] == '\r': line = line[:-1] return line
def formatted(self): '''should formatted output be used? It is often desirable to format the output to suite the output medium. Examples of this are truncating long lines or colorizing messages. However, this is not often not desirable when piping output into other utilities, e.g. `grep'. Formatted output is triggered by the value of the `ui.formatted' configuration variable or - if it is unset - when `sys.stdout' points to a terminal device. Please note that `ui.formatted' should be considered an implementation detail; it is not intended for use outside Mercurial or its extensions. This function refers to output only; for input, see `ui.interactive()'. This function always returns false when in plain mode, see `ui.plain()'. ''' if self.plain(): return False i = self.configbool("ui", "formatted", None) if i is None: # some environments replace stdout without implementing isatty # usually those are non-interactive return util.isatty(self.fout) return i
def interactive(self): '''is interactive input allowed? An interactive session is a session where input can be reasonably read from `sys.stdin'. If this function returns false, any attempt to read from stdin should fail with an error, unless a sensible default has been specified. Interactiveness is triggered by the value of the `ui.interactive' configuration variable or - if it is unset - when `sys.stdin' points to a terminal device. This function refers to input only; for output, see `ui.formatted()'. ''' i = self.configbool("ui", "interactive", None) if i is None: # some environments replace stdin without implementing isatty # usually those are non-interactive return util.isatty(self.fin) return i
def _readline(self, prompt=''): if util.isatty(self.fin): try: # magically add command line editing support, where # available import readline # force demandimport to really load the module readline.read_history_file # windows sometimes raises something other than ImportError except Exception: pass # instead of trying to emulate raw_input, swap our in/out # with sys.stdin/out old = sys.stdout, sys.stdin sys.stdout, sys.stdin = self.fout, self.fin line = raw_input(prompt) sys.stdout, sys.stdin = old # When stdin is in binary mode on Windows, it can cause # raw_input() to emit an extra trailing carriage return if os.linesep == '\r\n' and line and line[-1] == '\r': line = line[:-1] return line
def _isatty(self, fh): if self.configbool('ui', 'nontty', False): return False return util.isatty(fh)
def _isatty(self, fh): if self.configbool("ui", "nontty", False): return False return util.isatty(fh)