feat(prompt): readline line editing with per-session history
When stdin is a terminal the prompt is read with bash's readline, `IFS= read -e -r -p '> ' REPLY`, so the arrow keys no longer print escape garbage: Left/Right, Home/End, Ctrl-A/E, Backspace/Delete edit the line, and Up/Down walk the lines entered in this session (`history -s` for every line with a non-blank character; empty lines are not recorded). Down past the newest entry restores the line typed before Up, and Up at the oldest entry or Down on the new line ring the bell, as readline does by default. The Nx y/N answer is read the same way and never recorded. Nothing persists: HISTFILE is unset at startup and the history is never read or written. Verified on bash 4.3.48 and 5.2.15 that `read -e` and `history -s` share one history list in a non-interactive shell, that inherited HISTSIZE/HISTCONTROL/HISTIGNORE have no effect there, and that Ctrl-C at the prompt restores the terminal. readline draws the prompt on stderr, as bash does. Piped stdin keeps the plain `read -r` exactly, including the echo of each line and EOF => exit 2. New unit tests (tests/unit/lineedit.bats) drive a real pty with script(1): history recall, the bell at both ends, the stashed line, Left-arrow editing, the y/N answer kept out of the history, no history file under HOME/TMPDIR, ^D => exit 2. The E2E suite gets a pty smoke test (Up recalls 1?), skipped where the image has no script(1).
This commit is contained in:
1 parent
71d7f87aa3
commit
296c77e319
7 files changed
+183
-11
No files matched your search
@@ -147,6 +147,18 @@ replacements only the pacman transaction (`-Sup`) shows, packages dnf installs t
|
||||
others, packages a Tumbleweed `dist-upgrade` removes. With no row but such work, the list
|
||||
says "0 to review, but ... reports pending changes" and `<enter>` still runs the upgrade.
|
||||
|
||||
### Line editing and history
|
||||
|
||||
When stdin is a terminal, the prompt is read with bash's readline and its defaults: Left/Right
|
||||
move the cursor, Home/End or Ctrl-A/Ctrl-E jump to the ends, Backspace/Delete edit, and Up/Down
|
||||
walk the lines entered in this session. Down past the newest entry brings back what you had typed
|
||||
before pressing Up; Up at the oldest entry, and Down when already back on the new line, ring the
|
||||
terminal bell. Empty lines and the `y/N` answer of `Nx` are not recorded. The history lives in
|
||||
memory only and is never read from or written to a file (`HISTFILE` is ignored), so every run
|
||||
starts with an empty one. As in bash, readline draws the prompt and the line on stderr and honours
|
||||
your `~/.inputrc`. Piped or redirected stdin keeps the plain line reader: every line is echoed
|
||||
after the prompt, and end of input aborts (exit 2).
|
||||
|
||||
### Dry run
|
||||
|
||||
`--dry-run` prints every mutating command as `+ <command>` instead of running it:
|
||||
@@ -265,7 +277,8 @@ signal during the exit handler, the holds lock kept while a restore failed, jour
|
||||
zypper configuration replayed only when no other run holds their lock, the pacman pre-check /
|
||||
database install / `-Su` sequence and stale throwaway databases, statefile locking and merge,
|
||||
the `mkdir` lock fallback (EPERM owner alive, no busy loop), an inaccessible state directory, the
|
||||
sudo re-exec of the file itself and its loop guard).
|
||||
sudo re-exec of the file itself and its loop guard), and the prompt on a real pty (`script`):
|
||||
cursor editing, Up/Down history recall, the stashed line, the bell at both ends, no history file.
|
||||
About 30 seconds.
|
||||
|
||||
### End-to-end tests (`tests/e2e/`)
|
||||
@@ -288,7 +301,8 @@ excluding `su-dummy-b` (with and without a pre-existing hold/lock/IgnorePkg/excl
|
||||
`su-dummy-c`, which must survive byte for byte), trusting re-including an excluded
|
||||
dependency, full upgrade, `Nx` (refused for su-dummy-b, which su-dummy-a needs; su-dummy-a
|
||||
taking its dependency su-dummy-b along, shown in the prompt, and the unrelated orphan surviving),
|
||||
purging everything, `q`, end of input, `--dry-run`, the read-only commands as an unprivileged
|
||||
purging everything, `q`, end of input, a session on a pty where Up recalls the previous line
|
||||
(skipped where the image has no `script`), `--dry-run`, the read-only commands as an unprivileged
|
||||
user, plus per backend: pacman never touching the real sync database outside the upgrade and
|
||||
installing exactly the reviewed database at `<enter>` (same hash, a package published after the
|
||||
review is not installed), apt
|
||||
|
||||
Reference in new issue
Block a user