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
| Lint Skipped |
| Unit Tests Skipped |
| hgext3rd/interactiveui.py | ||
|---|---|---|
| 26 | 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–27 | 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–27 | \033[K clears a single line. I also don't want to clear to the end of the screen. | |
| hgext3rd/interactiveui.py | ||
|---|---|---|
| 26–27 | 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? | |
| # 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 | ||||
| from mercurial.i18n import _ | |||||
| from mercurial import ( | |||||
| error, | |||||
| ) | |||||
| def clearline(): | def clearline(): | ||||
| 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 | ||||
| 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"))): | for i in range(len(s.split("\n")) - 1): | ||||
| clearline() | clearline() | ||||
quark: Then you can get rid of the `for` loop:
clearline(s.count('\n')) | |||||
| s = viewobj.render() | s = viewobj.render() | ||||
| print(s) | sys.stdout.write(s) | ||||
Maybe make 1 as an argument, ex: clearline(n=1) and '\033[%dA\033[K' % n