##// END OF EJS Templates
Use the pager given by the environment to display long output...
David Soria Parra -
r6302:8e3dc3de default
parent child Browse files
Show More
@@ -522,6 +522,12 b' ui::'
522 Print debugging information. True or False. Default is False.
522 Print debugging information. True or False. Default is False.
523 editor;;
523 editor;;
524 The editor to use during a commit. Default is $EDITOR or "vi".
524 The editor to use during a commit. Default is $EDITOR or "vi".
525 pager;;
526 The pager that is used when displaying long output.
527 Default is $PAGER. If not set, the output is written to the
528 stdandard output.
529 usepager;;
530 If set to true, the system pager is used. True or False. Default is False.
525 fallbackencoding;;
531 fallbackencoding;;
526 Encoding to try if it's not possible to decode the changelog using
532 Encoding to try if it's not possible to decode the changelog using
527 UTF-8. Default is ISO-8859-1.
533 UTF-8. Default is ISO-8859-1.
@@ -31,6 +31,7 b' class ui(object):'
31 parentui=None):
31 parentui=None):
32 self.overlay = None
32 self.overlay = None
33 self.buffers = []
33 self.buffers = []
34 self.pager = None
34 if parentui is None:
35 if parentui is None:
35 # this is the parent of all ui children
36 # this is the parent of all ui children
36 self.parentui = None
37 self.parentui = None
@@ -64,6 +65,15 b' class ui(object):'
64 def __getattr__(self, key):
65 def __getattr__(self, key):
65 return getattr(self.parentui, key)
66 return getattr(self.parentui, key)
66
67
68 def __del__(self):
69 if self.pager:
70 try:
71 self.pager.close()
72 except IOException:
73 # we might get into an broken pipe if the users quit
74 # the pager before we finished io
75 pass
76
67 def isatty(self):
77 def isatty(self):
68 if ui._isatty is None:
78 if ui._isatty is None:
69 ui._isatty = sys.stdin.isatty()
79 ui._isatty = sys.stdin.isatty()
@@ -370,9 +380,14 b' class ui(object):'
370 return "".join(self.buffers.pop())
380 return "".join(self.buffers.pop())
371
381
372 def write(self, *args):
382 def write(self, *args):
383 """Write to a pager if available, otherwise to stdout"""
373 if self.buffers:
384 if self.buffers:
374 self.buffers[-1].extend([str(a) for a in args])
385 self.buffers[-1].extend([str(a) for a in args])
375 else:
386 else:
387 if self.getpager() and not self.pager:
388 self.pager = os.popen(self.getpager(), "w")
389 sys.stderr = self.pager
390 sys.stdout = self.pager
376 for a in args:
391 for a in args:
377 sys.stdout.write(str(a))
392 sys.stdout.write(str(a))
378
393
@@ -478,3 +493,8 b' class ui(object):'
478 os.environ.get("VISUAL") or
493 os.environ.get("VISUAL") or
479 os.environ.get("EDITOR", "vi"))
494 os.environ.get("EDITOR", "vi"))
480
495
496 def getpager(self):
497 '''return a pager'''
498 if self.configbool("ui", "usepager", False):
499 return (self.config("ui", "pager")
500 or os.environ.get("PAGER"))
General Comments 0
You need to be logged in to leave comments. Login now