This commit is contained in:
Joakim
2026-10-12 23:03:50 +02:00
parent 4227383e5c
commit 212b922629
2 changed files with 21 additions and 5 deletions

View File

@@ -38,3 +38,9 @@
## v2 update
- The bottom empty row now visibly shows the cursor.
- When TUI exits normally, the shell integration changes the parent Bash shell to the directory where TUI was closed.
## v2 fix – interactive shell commands and exit directory
- Fixed interactive action commands: the command loop no longer redirects stdin from the command file.
- Commands such as `unzip -l <path> && read -rp "Enter..." || read -rp "FAILED..."` now receive input from the real terminal.
- The final TUI directory is always applied to the parent Bash shell when TUI exits, including Ctrl+C/SIGINT.

View File

@@ -70,11 +70,16 @@ tui() {
# change the parent Bash shell to the directory where TUI was
# actually closed. This includes Ctrl+C (status 130).
if (( rc != 42 )); then
cd "$tui_cwd" || {
# The TUI writes its actual final directory in cwd_file in its
# finally block. Always apply it to the parent Bash shell before
# handling the exit status, including SIGINT/Ctrl+C.
if cd "$tui_cwd"; then
rm -f "$command_file" "$cwd_file"
else
printf 'tui: cannot cd to final directory: %s\n' "$tui_cwd" >&2
rm -f "$command_file" "$cwd_file"
return 1
}
rm -f "$command_file" "$cwd_file"
fi
if (( rc == 130 )); then
return 0
fi
@@ -90,7 +95,12 @@ tui() {
return 1
}
while IFS= read -r cmd; do
# Do not redirect stdin while executing commands: commands may need
# interactive input (for example `read`, `joe`, or `less`). Read the
# command list into an array first, then let each command inherit the
# real terminal stdin.
mapfile -t tui_commands < "$command_file"
for cmd in "${tui_commands[@]}"; do
[[ -z "$cmd" ]] && continue
history -s -- "$cmd"
@@ -102,7 +112,7 @@ tui() {
read -rp 'Tryck Enter för att fortsätta...' _
break
fi
done < "$command_file"
done
popd >/dev/null || true