colors, ../ och -a

This commit is contained in:
Joakim
2026-10-12 22:35:04 +02:00
parent 8deac25f00
commit 0b3179f4ff
3 changed files with 87 additions and 54 deletions

View File

@@ -28,3 +28,7 @@
- Cursor can now move to the empty line immediately below the last object.
- `Ctrl+K K` now behaves like joe: the block end is the row immediately above the cursor.
- On the bottom empty line, `Ctrl+K K` therefore selects through the last object.
## 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.

View File

@@ -44,19 +44,31 @@ tui() {
fi
rc=$?
tui_cwd="$(<"$cwd_file")"
if [[ -z "$tui_cwd" || ! -d "$tui_cwd" ]]; then
if (( rc != 42 )); then
rm -f "$command_file" "$cwd_file"
return "$rc"
fi
tui_cwd="$(<"$cwd_file")"
if [[ -z "$tui_cwd" || ! -d "$tui_cwd" ]]; then
echo "tui: invalid TUI working directory" >&2
rm -f "$command_file" "$cwd_file"
return 1
fi
# A normal TUI exit means the user wants to leave TUI. Change the
# parent Bash shell to the directory where TUI was actually closed.
if (( rc != 42 )); then
if (( rc == 0 )); then
cd "$tui_cwd" || {
rm -f "$command_file" "$cwd_file"
return 1
}
fi
rm -f "$command_file" "$cwd_file"
return "$rc"
fi
# Execute all commands belonging to one TUI action before starting
# TUI again. Each command remains a normal Bash command and gets its
# own history entry. If a command fails, stop the action and pause so

View File

@@ -443,10 +443,12 @@ def draw(stdscr, browser, status=""):
text = entry.name + ("/" if entry.is_dir() else "")
else:
# One empty line after the final object, matching the cursor range.
# A literal space is needed here: curses does not draw attributes
# for an empty string, so the cursor would otherwise be invisible.
entry = None
is_marked = False
attrs = curses.A_NORMAL
text = ""
text = " "
if index == browser.cursor:
attrs |= curses.A_UNDERLINE
@@ -502,6 +504,18 @@ def run(stdscr, start_dir=".", show_all=False):
status = ""
def save_cwd():
cwd_file = os.environ.get("TUI_CWD_FILE")
if cwd_file:
try:
Path(cwd_file).write_text(str(browser.path), encoding="utf-8")
except OSError:
pass
# Always leave the shell wrapper with the directory in which TUI was
# actually closed, not merely the directory of the last action.
save_cwd()
def configured_action(key):
if key == curses.KEY_UP:
return browser.resolve_key_action(["up"], browser.selected())
@@ -522,6 +536,7 @@ def run(stdscr, start_dir=".", show_all=False):
return None
try:
while True:
draw(stdscr, browser, status)
status = ""
@@ -578,6 +593,8 @@ def run(stdscr, start_dir=".", show_all=False):
return SHELL_HANDOFF
if result is False:
return
finally:
save_cwd()
def main():