From 8c31129813298da8d8ca9dd08ccad6632b348043 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Tue, 4 Aug 2020 18:47:15 +0300 Subject: [PATCH] one formatting function --- shfm | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/shfm b/shfm index e80d655..5984dbe 100755 --- a/shfm +++ b/shfm @@ -58,9 +58,9 @@ term_scroll_down() { y=$((y + 1)) y2=$((y2 + 1 < bottom ? y2 + 1 : bottom)) - print_line "$((y - 1))" "$@" + line_print "$((y - 1))" "$@" printf '\n' - print_line "$y" "$@" + line_print "$y" "$@" status_line "($y/$#) $PWD" ;; esac @@ -73,14 +73,14 @@ term_scroll_up() { *) y=$((y - 1)) - print_line "$((y + 1))" "$@" + line_print "$((y + 1))" "$@" case $y2 in 1) esc IL ;; *) esc CUU; y2=$((y2 > 1 ? y2 - 1 : 1)) esac - print_line "$y" "$@" + line_print "$y" "$@" status_line "($y/$#) $PWD" ;; esac @@ -147,18 +147,14 @@ list_print() { esac for file do - file_escape "$file" - case $i in "$y2") esc SGR 34 7 esac case $((i - end)) in -*) - printf %s "$safe" - esc SGR + line_format "$file" esc CUD - printf '\r' ;; esac @@ -202,7 +198,7 @@ prompt() { status_line "($y/$#) $PWD" } -print_line() { +line_print() { offset=$1 case $offset in @@ -210,18 +206,22 @@ print_line() { esac shift "$offset" - file_escape "$1" - esc EL0 - printf %s "$safe" - esc SGR - printf '\r' + line_format "$1" case $offset in "$y") cur=$1 esac } +line_format() { + file_escape "$1" + esc EL0 + printf %s "$safe" + esc SGR + printf '\r' +} + main() { set -e