Show More
@@ -70,8 +70,14 b' def _runpager(ui, p):' | |||||
70 | close_fds=util.closefds, stdin=subprocess.PIPE, |
|
70 | close_fds=util.closefds, stdin=subprocess.PIPE, | |
71 | stdout=sys.stdout, stderr=sys.stderr) |
|
71 | stdout=sys.stdout, stderr=sys.stderr) | |
72 |
|
72 | |||
|
73 | # back up original file objects and descriptors | |||
|
74 | olduifout = ui.fout | |||
|
75 | oldstdout = sys.stdout | |||
73 | stdoutfd = os.dup(sys.stdout.fileno()) |
|
76 | stdoutfd = os.dup(sys.stdout.fileno()) | |
74 | stderrfd = os.dup(sys.stderr.fileno()) |
|
77 | stderrfd = os.dup(sys.stderr.fileno()) | |
|
78 | ||||
|
79 | # create new line-buffered stdout so that output can show up immediately | |||
|
80 | ui.fout = sys.stdout = newstdout = os.fdopen(sys.stdout.fileno(), 'wb', 1) | |||
75 | os.dup2(pager.stdin.fileno(), sys.stdout.fileno()) |
|
81 | os.dup2(pager.stdin.fileno(), sys.stdout.fileno()) | |
76 | if ui._isatty(sys.stderr): |
|
82 | if ui._isatty(sys.stderr): | |
77 | os.dup2(pager.stdin.fileno(), sys.stderr.fileno()) |
|
83 | os.dup2(pager.stdin.fileno(), sys.stderr.fileno()) | |
@@ -81,6 +87,12 b' def _runpager(ui, p):' | |||||
81 | if util.safehasattr(signal, "SIGINT"): |
|
87 | if util.safehasattr(signal, "SIGINT"): | |
82 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
|
88 | signal.signal(signal.SIGINT, signal.SIG_IGN) | |
83 | pager.stdin.close() |
|
89 | pager.stdin.close() | |
|
90 | ui.fout = olduifout | |||
|
91 | sys.stdout = oldstdout | |||
|
92 | # close new stdout while it's associated with pager; otherwise stdout | |||
|
93 | # fd would be closed when newstdout is deleted | |||
|
94 | newstdout.close() | |||
|
95 | # restore original fds: stdout is open again | |||
84 | os.dup2(stdoutfd, sys.stdout.fileno()) |
|
96 | os.dup2(stdoutfd, sys.stdout.fileno()) | |
85 | os.dup2(stderrfd, sys.stderr.fileno()) |
|
97 | os.dup2(stderrfd, sys.stderr.fileno()) | |
86 | pager.wait() |
|
98 | pager.wait() |
General Comments 0
You need to be logged in to leave comments.
Login now