updated panel mode

This commit is contained in:
emmett1
2026-03-28 07:54:42 +08:00
parent 25a329aba9
commit 6b729ffe8a
+31 -4
View File
@@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
# sfm - Simple File Manager in POSIX sh # sfm - Simple File Manager in POSIX sh (flicker-free)
# version 0.4
# --- terminal control --- # --- terminal control ---
tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; } tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; }
@@ -456,10 +457,36 @@ draw_preview() {
case "$entry" in case "$entry" in
*/) */)
# directory: show entry count # directory: list contents
_dc=$(ls -1 "$_path" 2>/dev/null | wc -l | tr -d '[:space:]') _max_lines=$((_rows - 3))
_pr=2
for _de in "$_path"/*/; do
[ "$_pr" -gt $((_rows - 1)) ] && break
[ -d "$_de" ] || continue
_dn="${_de%/}"; _dn="${_dn##*/}"
[ "$_dn" = "*" ] && continue
_dl=" ${_dn}/"
[ "${#_dl}" -gt "$((_pw - 1))" ] && _dl="$(printf '%s' "$_dl" | cut -c1-$((_pw-2)))~"
goto "$_pr" "$_px"
printf '%s%s%s' "${GREEN}${BOLD}" "$_dl" "${RESET}"
_pr=$((_pr + 1))
done
for _fe in "$_path"/*; do
[ "$_pr" -gt $((_rows - 1)) ] && break
[ -e "$_fe" ] || continue
[ -d "$_fe" ] && continue
_fn="${_fe##*/}"
[ "$_fn" = "*" ] && continue
_fl=" ${_fn}"
[ "${#_fl}" -gt "$((_pw - 1))" ] && _fl="$(printf '%s' "$_fl" | cut -c1-$((_pw-2)))~"
goto "$_pr" "$_px"
printf '%s%s%s' "${WHITE}" "$_fl" "${RESET}"
_pr=$((_pr + 1))
done
if [ "$_pr" -eq 2 ]; then
goto 2 "$_px" goto 2 "$_px"
printf '%s[dir] %s items%s' "${CYAN}" "${_dc}" "${RESET}" printf '%s(empty)%s' "${WHITE}" "${RESET}"
fi
;; ;;
*@) *@)
# symlink # symlink