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
quark |
Restricted Project |
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
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
hgext3rd/interactiveui.py | ||
---|---|---|
26–27 | Maybe make 1 as an argument, ex: clearline(n=1) and '\033[%dA\033[K' % n | |
134–135 | Then you can get rid of the for loop: clearline(s.count('\n')) | |
hgext3rd/undo.py | ||
656–658 | The crecord interface uses key: effect pattern. Maybe use the same: <-: next ->: previous q: abort enter: confirm |
hgext3rd/interactiveui.py | ||
---|---|---|
26–28 | I meant this could be simplified to: w.write('\033[%dA\033[K' % n) without a for loop. Have you tried that? |
hgext3rd/interactiveui.py | ||
---|---|---|
26–28 | \033[K clears a single line. I also don't want to clear to the end of the screen. |
hgext3rd/interactiveui.py | ||
---|---|---|
26–28 | I see. This turns out to be an area that my local Linux terminal behaviors differently (it does not even require \033K to clear lines). I checked another project. It does \033[%dA first to move up multiple lines. Then change the output string - insert \033[K for each line. That seems better to avoid flashing. Maybe we can try that? |
Path | Packages | |||
---|---|---|---|---|
M | hgext3rd/interactiveui.py (20 lines) | |||
M | hgext3rd/undo.py (22 lines) | |||
M | tests/test-undo.t (2 lines) |
# interactiveui.py: display information and allow for left/right control | # interactiveui.py: display information and allow for left/right control | ||||
# | # | ||||
# Copyright 2017 Facebook, Inc. | # Copyright 2017 Facebook, Inc. | ||||
# | # | ||||
# This software may be used and distributed according to the terms of the | # This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | # GNU General Public License version 2 or any later version. | ||||
from __future__ import absolute_import | from __future__ import absolute_import | ||||
import os | import os | ||||
import sys | import sys | ||||
import termios | import termios | ||||
import tty | import tty | ||||
def clearline(): | from mercurial.i18n import _ | ||||
from mercurial import ( | |||||
error, | |||||
) | |||||
def clearline(n=1): | |||||
w = sys.stdout | w = sys.stdout | ||||
# ANSI | # ANSI | ||||
# ESC[#A : up # lines | # ESC[#A : up # lines | ||||
# ESC[K : clear to end of line | # ESC[K : clear to end of line | ||||
for i in range(n): | |||||
w.write('\033[1A\033[K') | w.write('\033[1A\033[K') | ||||
quark: Maybe make `1` as an argument, ex: `clearline(n=1)` and `'\033[%dA\033[K' % n` | |||||
w.flush() | w.flush() | ||||
I meant this could be simplified to: w.write('\033[%dA\033[K' % n) without a for loop. Have you tried that? quark: I meant this could be simplified to:
w.write('\033[%dA\033[K' % n)
without a `for` loop. | |||||
\033[K clears a single line. I also don't want to clear to the end of the screen. felixmerk: \033[K clears a single line. I also don't want to clear to the end of the screen. | |||||
I see. This turns out to be an area that my local Linux terminal behaviors differently (it does not even require \033K to clear lines). I checked another project. It does \033[%dA first to move up multiple lines. Then change the output string - insert \033[K for each line. That seems better to avoid flashing. Maybe we can try that? quark: I see. This turns out to be an area that my local Linux terminal behaviors differently (it does… | |||||
# From: | # From: | ||||
# https://github.com/pallets/click/blob/master/click/_termui_impl.py#L534 | # https://github.com/pallets/click/blob/master/click/_termui_impl.py#L534 | ||||
# As per licence: | # As per licence: | ||||
# Copyright (c) 2014 by Armin Ronacher. | # Copyright (c) 2014 by Armin Ronacher. | ||||
# | # | ||||
# Click uses parts of optparse written by Gregory P. Ward and maintained by | # Click uses parts of optparse written by Gregory P. Ward and maintained by | ||||
# the Python software foundation. This is limited to code in the parser.py | # the Python software foundation. This is limited to code in the parser.py | ||||
# handle user keypress left arrow | # handle user keypress left arrow | ||||
pass | pass | ||||
def rightarrow(): | def rightarrow(): | ||||
# handle user keypress right arrow | # handle user keypress right arrow | ||||
pass | pass | ||||
def view(viewobj): | def view(viewobj): | ||||
done = False | done = False | ||||
if viewobj.ui.pageractive: | |||||
raise error.Abort(_("interactiveui doesn't work with pager")) | |||||
s = viewobj.render() | s = viewobj.render() | ||||
print(s) | sys.stdout.write(s) | ||||
while not done: | while not done: | ||||
output = getchar(sys.stdin.fileno()) | output = getchar(sys.stdin.fileno()) | ||||
if repr(output) == '\'q\'': | if repr(output) == '\'q\'': | ||||
done = True | done = True | ||||
break | break | ||||
if repr(output) == '\'\\r\'': | if repr(output) == '\'\\r\'': | ||||
# \r = return | # \r = return | ||||
viewobj.enter() | viewobj.enter() | ||||
done = True | done = True | ||||
break | break | ||||
if repr(output) == '\'\\x1b[C\'': | if repr(output) == '\'\\x1b[C\'': | ||||
viewobj.rightarrow() | viewobj.rightarrow() | ||||
if repr(output) == '\'\\x1b[D\'': | if repr(output) == '\'\\x1b[D\'': | ||||
viewobj.leftarrow() | viewobj.leftarrow() | ||||
for i in range(len(s.split("\n"))): | clearline(s.count("\n")) | ||||
quark: Then you can get rid of the `for` loop:
clearline(s.count('\n')) | |||||
clearline() | |||||
s = viewobj.render() | s = viewobj.render() | ||||
print(s) | sys.stdout.write(s) |
| | | | ||||
~ | ~ | ||||
o | o | ||||
| | | | ||||
~ | ~ | ||||
o | o | ||||
| | | | ||||
~ | ~ | ||||
undo to *, before ci -m prev1 (glob) | |||||
$ hg undo -p -n 2 | $ hg undo -p -n 2 | ||||
@ Undone | @ Undone | ||||
| | | | ||||
o Undone | o Undone | ||||
| | | | ||||
| o | | o | ||||
|/ | |/ | ||||
o | o | ||||
| | | | ||||
o | o | ||||
| | | | ||||
o | o | ||||
| | | | ||||
~ | ~ | ||||
o | o | ||||
| | | | ||||
~ | ~ | ||||
o | o | ||||
| | | | ||||
~ | ~ | ||||
undo to *, before undo -b 3532 (glob) | |||||
hg redo tests | hg redo tests | ||||
$ hg log -G -T compact | $ hg log -G -T compact | ||||
@ 23[tip] a0b72b3048d6 1970-01-01 00:00 +0000 test | @ 23[tip] a0b72b3048d6 1970-01-01 00:00 +0000 test | ||||
| prev1 | | prev1 | ||||
| | | | ||||
o 22:18 3ee6a6880888 1970-01-01 00:00 +0000 test | o 22:18 3ee6a6880888 1970-01-01 00:00 +0000 test | ||||
| a9 | | a9 |
Maybe make 1 as an argument, ex: clearline(n=1) and '\033[%dA\033[K' % n