From e45f91221168215dd601c0eaf344a7eccd47e344 Mon Sep 17 00:00:00 2001 From: Felix Merk Date: Mon, 21 Aug 2017 11:25:36 -0700 Subject: [PATCH] undo: preview shows command and time output Makes hg undo -i and hg undo -p output show an "undo to time, before command" message and adds directions (left, right, return, q). Also adds pager check as pager break interactiveui. Testing: run hg undo -p and hg undo -i and see output Differential Revision: https://phab.mercurial-scm.org/D448 --- hgext3rd/interactiveui.py | 20 ++++++++++++++------ hgext3rd/undo.py | 22 ++++++++++++++++++++-- tests/test-undo.t | 2 ++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/hgext3rd/interactiveui.py b/hgext3rd/interactiveui.py index 6cba09a867..3d829f360c 100644 --- a/hgext3rd/interactiveui.py +++ b/hgext3rd/interactiveui.py @@ -12,12 +12,19 @@ import sys import termios import tty -def clearline(): +from mercurial.i18n import _ + +from mercurial import ( + error, +) + +def clearline(n=1): w = sys.stdout # ANSI # ESC[#A : up # lines # ESC[K : clear to end of line - w.write('\033[1A\033[K') + for i in range(n): + w.write('\033[1A\033[K') w.flush() # From: @@ -107,8 +114,10 @@ class viewframe(object): def view(viewobj): done = False + if viewobj.ui.pageractive: + raise error.Abort(_("interactiveui doesn't work with pager")) s = viewobj.render() - print(s) + sys.stdout.write(s) while not done: output = getchar(sys.stdin.fileno()) if repr(output) == '\'q\'': @@ -123,7 +132,6 @@ def view(viewobj): viewobj.rightarrow() if repr(output) == '\'\\x1b[D\'': viewobj.leftarrow() - for i in range(len(s.split("\n"))): - clearline() + clearline(s.count("\n")) s = viewobj.render() - print(s) + sys.stdout.write(s) diff --git a/hgext3rd/undo.py b/hgext3rd/undo.py index b82aab55ba..b439a4da90 100644 --- a/hgext3rd/undo.py +++ b/hgext3rd/undo.py @@ -653,6 +653,10 @@ def undo(ui, repo, *args, **opts): ui = self.ui ui.pushbuffer() _preview(ui, self.repo, self.index) + repo.ui.status(_("<-: next " + "->: previous " + "q: abort " + "enter: confirm\n")) return ui.popbuffer() def rightarrow(self): self.index += 1 @@ -862,8 +866,8 @@ def _undoto(ui, repo, reverseindex, keep=False, branch=None): commandstr = _readnode(repo, "command.i", nodedict["command"]) commandlist = commandstr.split("\0")[1:] commandstr = " ".join(commandlist) - uimessage = 'undone to %s, before %s\n' % (time, commandstr) - repo.ui.status(_(uimessage)) + uimessage = _('undone to %s, before %s\n') % (time, commandstr) + repo.ui.status((uimessage)) def _computerelative(repo, reverseindex, absolute=False, branch=""): # allows for relative undos using @@ -1069,6 +1073,9 @@ def _preview(ui, repo, reverseindex): # None # override "UNDOINDEX" as a variable usable in template + if not _gapcheck(ui, repo, reverseindex): + repo.ui.status(_("WARN: missing history between present and this" + " state\n")) overrides = { ('templates', 'UNDOINDEX'): str(reverseindex), } @@ -1082,6 +1089,17 @@ def _preview(ui, repo, reverseindex): try: with ui.configoverride(overrides): cmdutil.graphlog(ui, repo, None, opts) + # informative output + nodedict = _readindex(repo, reverseindex) + time = _readnode(repo, "date.i", nodedict["date"]) + time = util.datestr([float(x) for x in time.split(" ")]) + + nodedict = _readindex(repo, reverseindex - 1) + commandstr = _readnode(repo, "command.i", nodedict["command"]) + commandlist = commandstr.split("\0")[1:] + commandstr = " ".join(commandlist) + uimessage = _('undo to %s, before %s\n') % (time, commandstr) + repo.ui.status((uimessage)) except IndexError: # don't print anything pass diff --git a/tests/test-undo.t b/tests/test-undo.t index 6a84116862..417cc06a4e 100644 --- a/tests/test-undo.t +++ b/tests/test-undo.t @@ -734,6 +734,7 @@ hg undo --preview test o | ~ + undo to *, before ci -m prev1 (glob) $ hg undo -p -n 2 @ Undone | @@ -754,6 +755,7 @@ hg undo --preview test o | ~ + undo to *, before undo -b 3532 (glob) hg redo tests $ hg log -G -T compact