pytest-tui icon indicating copy to clipboard operation
pytest-tui copied to clipboard

Support key presses (and later, keymaps) in TUIs

Open jeffwright13 opened this issue 3 years ago • 3 comments

jeffwright13 avatar Feb 19 '22 07:02 jeffwright13

Per Dave S: "having vim and emacs like bindings for navigating tabs and windows and searching would be a pro to see right up front for many terminal users I think."

jeffwright13 avatar May 02 '22 12:05 jeffwright13

Perhaps use Pygments as a template? Screen Shot 2022-05-02 at 6 23 52 AM

jeffwright13 avatar May 02 '22 12:05 jeffwright13

Per @jsh:

I use vi-mode in bash (set -o vi), so I'll just play on the command line for a few minutes and jot down what I see myself using:

ctl-[ (control open-bracket): This combo sends an escape, which vi uses to switch to command mode. I suppose I could hit the escape key instead, but this is under my fingers, and now in my wetware.
h,j,k,l: (left, down, up, right).  I could use arrow keys, but don't. See above. :-)
^, $: (beginning and end of line)
/: (search forwards). On the command line, this looks back through history.
n
?: (search backwards). When I'm already looking through history, this looks the other direction. Not so common, in bash, but just as common as '/' in vi.
n: Look for the same string, again, in the same direction.
f: (search forwards in a line).  When I want to change something in the middle of a recalled command, I use 'f' to go directly to that character, or one nearby, and then change it.
; : (semicolon -- look forward again). If I find the first instance of a character in the line with 'f', but that's not the one I want to change, jumps me to the next instance.
F and , : (capital 'f' and comma -- look backwards in the line).  These jump through the line, just like 'f' and ';', but in the opposite direction.
r: (replace). Replace a character.
R: (overwrite). Overwrite a string of characters.
A, I: (Append and Insert). Stick stuff on the end ('A') or beginning ('I') of the line.  'A' is really useful if I want to recall a pipeline and stick another step at the end.

When I want to turn some-command-line  into some-other-command $(some-command-line), my fingers say
ctl-[   # command-mode
/some-command-line ENTER # search the history for some-command-line
I some-other-command $( # stick some-other-command at the beginning of the line
ctl-[ # command mode again
A ) # stick a close paren on the end of the line
ENTER # execute the new command line

The bash emacs mode (set -o emacs, the default) lets you edit the command line with EMACS keybindings instead.

Apps other than bash can supply both conveniences -- vi and emacs editing of command history -- with the GNU Readline package.
I just googled, and I *think* that's what [this supplies](https://pymotw.com/3/readline/) for Python programs, but I haven't tried it yet.

jeffwright13 avatar Sep 19 '22 02:09 jeffwright13