got rid of mangaterm handling stdin

master
Alex 2022-09-17 14:37:31 -05:00
parent 9edb6d26c1
commit ac72802e5a
1 changed files with 7 additions and 50 deletions

View File

@ -1,6 +1,4 @@
#!/bin/bash
set -e
#!/bin/sh
#using PID for dirname in case multiple instances are opened they do not interfere
CACHEDIR="$HOME/.cache/mangaterm"
@ -15,7 +13,7 @@ read_char() {
}
help() {
echo "Read manga/comics in the terminal"
echo "Read manga/comics/pdfs in the terminal"
echo " mangaterm.sh DIRECTORY"
echo " mangaterm.sh FILE"
echo ""
@ -98,53 +96,12 @@ handleFile() {
trap 'close' 2
trap 'close' 15
[ "$1" = "--help" ] && help
if [ "$#" -gt 0 ]; then
mkdir -p "$TMPDIR"
if [ "$(echo "$1" | cut -c1-1)" = "-" ]; then
foot -e mangaterm "$2" 2>/dev/null > /dev/null
fi
handleFile "$1"
else
LINES=()
while IFS= read -r line; do
LINES+=("$line")
done
echo "${LINES[0]}"
echo "$I"
LEN="${#LINES[@]}"
I=0
while read -r -n 1 char < /dev/tty; do
if [ "$char" = "j" ]; then
I=$((I + 1))
elif [ "$char" = "k" ]; then
I=$((I - 1))
elif [ "$char" = "q" ]; then
close
fi
if [ "$I" -ge "$LEN" ] || [ "$I" -le "0" ]; then
if [ "$I" -ge "$LEN" ]; then
I="$LEN"
elif [ "$I" -lt "0" ]; then
I=0
fi
fi
echo "${LINES["$I"]}"
echo "$I"
done
close
mkdir -p "$TMPDIR"
if [ "$(echo "$1" | cut -c1-1)" = "-" ]; then
foot -e mangaterm "$2" 2>/dev/null > /dev/null
fi
handleFile "$1"