purge all scrolling code ugly

This commit is contained in:
Dylan Araps committed 2020-08-03 16:50:11 +03:00
1 parent db48ab5afd
commit 7c0416c737
2 files changed
+5 -81

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
shfm shfm [wip]
________________________________________________________________________________ ________________________________________________________________________________
wip file manager written in posix shell wip file manager written in posix shell
+4 -80
View File
@@ -1,7 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
# term_ {{{
term_setup() { term_setup() {
stty -icanon -echo stty -icanon -echo
@@ -21,53 +19,28 @@ term_resize() {
LINES=$1 COLUMNS=$2 LINES=$1 COLUMNS=$2
max_lines=$((LINES - 4)) # leave gap above statusline
} max_lines=$((LINES - 2))
# }}}
# key_ {{{
key_read() {
dd ibs=1 count=1 2>/dev/null
} }
key_handle() { key_handle() {
case $key$esc in case $key$esc in
k?|A2) # ARROW UP k?|A2) # ARROW UP
: "$((y_abs = y_abs - 1 < 0 ? 0 : y_abs - 1))"
;; ;;
j?|B2) # ARROW DOWN j?|B2) # ARROW DOWN
: "$((y_abs = y_abs + 1 >= dirc ? y_abs : y_abs + 1))"
;; ;;
l?|C2) # ARROW RIGHT l?|C2) # ARROW RIGHT
if cd "$cur"; then
y_abs=0
y_rel=0
else
term_reset
"${EDITOR:-vi}" "$cur"
term_setup
fi
;; ;;
h?|D2) # ARROW LEFT h?|D2) # ARROW LEFT
cd ..
y_abs=0
y_rel=0
dirc=0
;; ;;
g?) g?)
y_abs=0
y_rel=0
;; ;;
G?) G?)
y_abs=$dirc
;; ;;
q?) q?)
@@ -81,52 +54,8 @@ key_handle() {
esac esac
} }
# }}}
# dir_ {{{
dir_print() {
printf '\033[2J\033[H'
set -- *;
dirc=$#
i=0
if [ "$y_abs" -eq "$max_lines" ]; then
y_rel=$((max_lines))
elif [ "$y_abs" -gt "$max_lines" ]; then
shift "$((y_abs - max_lines))"
else
y_rel=$y_abs
fi
while [ "$i" -le "$max_lines" ]; do
case $i in
"$y_rel")
printf '\033[31;7m%s\033[m\n' "$1"
cur=$1
;;
*)
printf '%s\n' "$1"
;;
esac
shift 1;
i=$((i + 1));
[ "$1" ] || break;
done
}
# }}}
redraw() { redraw() {
dir_print status_line
status_line "$y_rel/$y_abs"
} }
status_line() { status_line() {
@@ -138,11 +67,6 @@ main() {
# change directory to the first argument # change directory to the first argument
cd "${1:-"$PWD"}" cd "${1:-"$PWD"}"
# todo: code should handle unset vars
y_abs=0
y_rel=0
dirc=0
term_resize term_resize
term_setup term_setup
redraw redraw
@@ -150,7 +74,7 @@ main() {
trap 'term_reset' EXIT INT trap 'term_reset' EXIT INT
trap 'term_resize; redraw' WINCH trap 'term_resize; redraw' WINCH
while key=$(key_read); do while key=$(dd ibs=1 count=1 2>/dev/null); do
key_handle "$key" key_handle "$key"
redraw redraw
done done