Show More
@@ -35,43 +35,9 b' would take the last num characters, or `' | |||||
35 | characters. |
|
35 | characters. | |
36 | """ |
|
36 | """ | |
37 |
|
37 | |||
38 | from mercurial import progress |
|
|||
39 | from mercurial import ui as uimod |
|
|||
40 |
|
||||
41 | def uisetup(ui): |
|
38 | def uisetup(ui): | |
42 | class progressui(ui.__class__): |
|
39 | if ui.config('progress', 'disable', None) is None: | |
43 | _progbar = None |
|
40 | ui.setconfig('progress', 'disable', 'False', 'hgext-progress') | |
44 |
|
||||
45 | def _quiet(self): |
|
|||
46 | return self.debugflag or self.quiet |
|
|||
47 |
|
||||
48 | def progress(self, *args, **opts): |
|
|||
49 | if not self._quiet(): |
|
|||
50 | self._progbar.progress(*args, **opts) |
|
|||
51 | return super(progressui, self).progress(*args, **opts) |
|
|||
52 |
|
||||
53 | def write(self, *args, **opts): |
|
|||
54 | if not self._quiet() and self._progbar.printed: |
|
|||
55 | self._progbar.clear() |
|
|||
56 | return super(progressui, self).write(*args, **opts) |
|
|||
57 |
|
||||
58 | def write_err(self, *args, **opts): |
|
|||
59 | if not self._quiet() and self._progbar.printed: |
|
|||
60 | self._progbar.clear() |
|
|||
61 | return super(progressui, self).write_err(*args, **opts) |
|
|||
62 |
|
||||
63 | # Apps that derive a class from ui.ui() can use |
|
|||
64 | # setconfig('progress', 'disable', 'True') to disable this extension |
|
|||
65 | if ui.configbool('progress', 'disable'): |
|
|||
66 | return |
|
|||
67 | if progress.shouldprint(ui) and not ui.debugflag and not ui.quiet: |
|
|||
68 | dval = object() |
|
|||
69 | if getattr(ui, '_progbar', dval) is dval: |
|
|||
70 | ui.__class__ = progressui |
|
|||
71 | # we instantiate one globally-shared progress bar to avoid |
|
|||
72 | # competing progress bars when multiple UI objects get created |
|
|||
73 | if not progressui._progbar: |
|
|||
74 | progressui._progbar = uimod.getprogbar(ui) |
|
|||
75 |
|
41 | |||
76 | def reposetup(ui, repo): |
|
42 | def reposetup(ui, repo): | |
77 | uisetup(repo.ui) |
|
43 | uisetup(repo.ui) |
@@ -584,6 +584,7 b' class ui(object):' | |||||
584 | "cmdname.type" is recommended. For example, status issues |
|
584 | "cmdname.type" is recommended. For example, status issues | |
585 | a label of "status.modified" for modified files. |
|
585 | a label of "status.modified" for modified files. | |
586 | ''' |
|
586 | ''' | |
|
587 | self._progclear() | |||
587 | if self._buffers: |
|
588 | if self._buffers: | |
588 | self._buffers[-1].extend([str(a) for a in args]) |
|
589 | self._buffers[-1].extend([str(a) for a in args]) | |
589 | else: |
|
590 | else: | |
@@ -591,6 +592,7 b' class ui(object):' | |||||
591 | self.fout.write(str(a)) |
|
592 | self.fout.write(str(a)) | |
592 |
|
593 | |||
593 | def write_err(self, *args, **opts): |
|
594 | def write_err(self, *args, **opts): | |
|
595 | self._progclear() | |||
594 | try: |
|
596 | try: | |
595 | if self._bufferstates and self._bufferstates[-1][0]: |
|
597 | if self._bufferstates and self._bufferstates[-1][0]: | |
596 | return self.write(*args, **opts) |
|
598 | return self.write(*args, **opts) | |
@@ -886,6 +888,22 b' class ui(object):' | |||||
886 | os.environ.get("VISUAL") or |
|
888 | os.environ.get("VISUAL") or | |
887 | os.environ.get("EDITOR", editor)) |
|
889 | os.environ.get("EDITOR", editor)) | |
888 |
|
890 | |||
|
891 | @util.propertycache | |||
|
892 | def _progbar(self): | |||
|
893 | """setup the progbar singleton to the ui object""" | |||
|
894 | if (self.quiet or self.debugflag | |||
|
895 | or self.configbool('progress', 'disable', True) | |||
|
896 | or not progress.shouldprint(self)): | |||
|
897 | return None | |||
|
898 | return getprogbar(self) | |||
|
899 | ||||
|
900 | def _progclear(self): | |||
|
901 | """clear progress bar output if any. use it before any output""" | |||
|
902 | if '_progbar' not in vars(self): # nothing loadef yet | |||
|
903 | return | |||
|
904 | if self._progbar is not None and self._progbar.printed: | |||
|
905 | self._progbar.clear() | |||
|
906 | ||||
889 | def progress(self, topic, pos, item="", unit="", total=None): |
|
907 | def progress(self, topic, pos, item="", unit="", total=None): | |
890 | '''show a progress message |
|
908 | '''show a progress message | |
891 |
|
909 | |||
@@ -902,7 +920,9 b' class ui(object):' | |||||
902 | All topics should be marked closed by setting pos to None at |
|
920 | All topics should be marked closed by setting pos to None at | |
903 | termination. |
|
921 | termination. | |
904 | ''' |
|
922 | ''' | |
905 |
|
923 | if self._progbar is not None: | ||
|
924 | self._progbar.progress(topic, pos, item=item, unit=unit, | |||
|
925 | total=total) | |||
906 | if pos is None or not self.configbool('progress', 'debug'): |
|
926 | if pos is None or not self.configbool('progress', 'debug'): | |
907 | return |
|
927 | return | |
908 |
|
928 |
@@ -258,6 +258,7 b' Enable progress extension for archive te' | |||||
258 | > [extensions] |
|
258 | > [extensions] | |
259 | > progress = |
|
259 | > progress = | |
260 | > [progress] |
|
260 | > [progress] | |
|
261 | > disable=False | |||
261 | > assume-tty = 1 |
|
262 | > assume-tty = 1 | |
262 | > delay = 0 |
|
263 | > delay = 0 | |
263 | > # set changedelay really large so we don't see nested topics |
|
264 | > # set changedelay really large so we don't see nested topics |
General Comments 0
You need to be logged in to leave comments.
Login now