some changes to mangaterm

master
Alex 2022-09-17 03:48:11 -05:00
parent ad8e4780e8
commit 9edb6d26c1
1 changed files with 54 additions and 7 deletions

View File

@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash
set -e
#using PID for dirname in case multiple instances are opened they do not interfere
CACHEDIR="$HOME/.cache/mangaterm"
@ -17,11 +19,14 @@ help() {
echo " mangaterm.sh DIRECTORY"
echo " mangaterm.sh FILE"
echo ""
echo " --help show this help menu"
echo ""
echo "keybindings:"
echo " j -> next page"
echo " k -> previous page"
echo " q -> quit"
echo ""
exit
}
disp() {
@ -55,7 +60,6 @@ readDir() {
disp "1"
I=1
#TODO this read is bash specific
while read_char char; do
if [ "$char" = "j" ]; then
I=$((I + 1))
@ -94,10 +98,53 @@ handleFile() {
trap 'close' 2
trap 'close' 15
mkdir -p "$TMPDIR"
if [ "$(echo "$1" | cut -c1-1)" = "-" ]; then
[ "$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
fi
handleFile "$1"
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
fi