def _runpager(p): if not util.safehasattr(os, 'fork'): sys.stdout = util.popen(p, 'wb') if util.isatty(sys.stderr): sys.stderr = sys.stdout return fdin, fdout = os.pipe() pid = os.fork() if pid == 0: os.close(fdin) os.dup2(fdout, sys.stdout.fileno()) if util.isatty(sys.stderr): os.dup2(fdout, sys.stderr.fileno()) os.close(fdout) return os.dup2(fdin, sys.stdin.fileno()) os.close(fdin) os.close(fdout) try: os.execvp('/bin/sh', ['/bin/sh', '-c', p]) except OSError, e: if e.errno == errno.ENOENT: # no /bin/sh, try executing the pager directly args = shlex.split(p) os.execvp(args[0], args) else: raise
def _runpager(p): pager = subprocess.Popen(p, shell=True, bufsize=-1, close_fds=util.closefds, stdin=subprocess.PIPE, stdout=sys.stdout, stderr=sys.stderr) stdout = os.dup(sys.stdout.fileno()) stderr = os.dup(sys.stderr.fileno()) os.dup2(pager.stdin.fileno(), sys.stdout.fileno()) if util.isatty(sys.stderr): os.dup2(pager.stdin.fileno(), sys.stderr.fileno()) @atexit.register def killpager(): pager.stdin.close() os.dup2(stdout, sys.stdout.fileno()) os.dup2(stderr, sys.stderr.fileno()) pager.wait()
def uisetup(ui): if ui.plain() or '--debugger' in sys.argv or not util.isatty(sys.stdout): return def pagecmd(orig, ui, options, cmd, cmdfunc): p = ui.config("pager", "pager", os.environ.get("PAGER")) if p: attend = ui.configlist('pager', 'attend', attended) auto = options['pager'] == 'auto' always = util.parsebool(options['pager']) if (always or auto and (cmd in attend or (cmd not in ui.configlist('pager', 'ignore') and not attend))): ui.setconfig('ui', 'formatted', ui.formatted()) ui.setconfig('ui', 'interactive', False) if util.safehasattr(signal, "SIGPIPE"): signal.signal(signal.SIGPIPE, signal.SIG_DFL) _runpager(p) return orig(ui, options, cmd, cmdfunc) extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
def shouldprint(ui): return util.isatty(sys.stderr) or ui.configbool('progress', 'assume-tty')