Improved search result force-download support

This commit is contained in:
Luxferre
2023-03-29 18:07:25 +03:00
parent 538c6520f4
commit 6e0d3ac2d3
2 changed files with 12 additions and 12 deletions
+11 -10
View File
@@ -39,13 +39,14 @@ fi
[[ -z "$BOPHER_DLDIR" ]] && BOPHER_DLDIR="$PWD" # downloads directory
# styling used in the TUI
ESC="\x1b"
ESC=$'\x1b' # use the ANSI literal syntax to support in read prompts as well
ERESET="$ESC[0m" # reset the styling
ERRCOLOR="$ESC[31;1m" # red bold
LINKCOLOR="$ESC[36;1m" # cyan bold
FOCUSATTR="$ESC[7;2m" # swap foreground and background and brightness level
CLS="$ESC[2J" # clear the entire screen
CURRESET="$ESC[0;0H" # reset the visual cursor
CURSTART="$ESC[1G" # move cursor to the start of the line
LINECLR="$ESC[2K" # clear current line
BELOWCLR="$ESC[0J" # clear everything below
ALTBUFON="$ESC[?47h" # use the alternative screen buffer
@@ -117,24 +118,25 @@ amtogopher() { # args: AM line
}
# AM entry clicker function
amclick() { # args: AM line, output: AM line(s)
amclick() { # args: AM line[, forcedl], output: AM line(s)
readarray -d $'\t' -t fields < <(printf '%s' "$1")
local action="${fields[0]}"
local desc="${fields[1]}"
local rhost="${fields[2]}"
local rport="${fields[3]}"
local sel="${fields[4]}"
local input=''
if [[ 'I' == "$action" ]]; then
read -p "${LINECLR}${CURSTART}Enter input for $rhost: " input
fi
[[ ! -z "$2" ]] && action='D' # force the download action
if [[ 'D' == "$action" ]]; then # download
local fname="${sel##*/}" # pure-bash version of basename
[[ -z "$fname" ]] && fname='dl.dat' # just make sure that it's not empty
gophetch "$rhost" "$rport" "$sel" > "$BOPHER_DLDIR/$fname"
[[ ! -z "$input" ]] && fname="${fname}%09${input}.search.txt"
gophetch "$rhost" "$rport" "$sel" "$input" > "$BOPHER_DLDIR/$fname"
printf 'E\tDownloaded %s to %s\n' "$(amtogopher "$1")" "$BOPHER_DLDIR/$fname"
elif [[ 'I' == "$action" || 'M' == "$action" || 'P' == "$action" ]]; then # text content
local input=''
if [[ 'I' == "$action" ]]; then
printf '%b' "$LINECLR" # clear the current line on the terminal
read -p "Enter input for $rhost: " input
fi
readarray -t lines < <(gophetch "$rhost" "$rport" "$sel" "$input")
for line in "${lines[@]}"; do # iterate over every fetched line
if [[ 'P' == "$action" ]]; then # generate a plaintext AM entry
@@ -216,8 +218,7 @@ jumplink() { # args: delta (usually 1 or -1)
amload() { # args: AM line[, forcedl]
CURRENTAM="$1" # update current AM value
printf '%b' "${LINECLR}Loading..."
[[ ! -z "$2" ]] && CURRENTAM="D${CURRENTAM:1}" # modify CURRENTAM first char to the download type
readarray -t SCREENBUF < <(amclick "$CURRENTAM") # populate screen buffer by loading the resource from the AM entry
readarray -t SCREENBUF < <(amclick "$CURRENTAM" "$2") # populate screen buffer by loading the resource from the AM entry
NAVIGABLES=() # reset the navigable indexes
CURLINKINDEX=0 # reset the link number
CURSCROLLPOS=0 # reset the scrolling position