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
+1 -2
View File
@@ -77,7 +77,6 @@ Bopher-NG's mouse input is supported on any terminals that support the 1000 **an
Note that this support is required at the client side only. For instance, you can safely run `bopher-ng.sh` on any compatible Bash version in an SSH session on your terminal and still be able to use mouse there. Note that this support is required at the client side only. For instance, you can safely run `bopher-ng.sh` on any compatible Bash version in an SSH session on your terminal and still be able to use mouse there.
## What is the license on this? ## What is the license on this?
Fully public domain Fully public domain.
+11 -10
View File
@@ -39,13 +39,14 @@ fi
[[ -z "$BOPHER_DLDIR" ]] && BOPHER_DLDIR="$PWD" # downloads directory [[ -z "$BOPHER_DLDIR" ]] && BOPHER_DLDIR="$PWD" # downloads directory
# styling used in the TUI # 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 ERESET="$ESC[0m" # reset the styling
ERRCOLOR="$ESC[31;1m" # red bold ERRCOLOR="$ESC[31;1m" # red bold
LINKCOLOR="$ESC[36;1m" # cyan bold LINKCOLOR="$ESC[36;1m" # cyan bold
FOCUSATTR="$ESC[7;2m" # swap foreground and background and brightness level FOCUSATTR="$ESC[7;2m" # swap foreground and background and brightness level
CLS="$ESC[2J" # clear the entire screen CLS="$ESC[2J" # clear the entire screen
CURRESET="$ESC[0;0H" # reset the visual cursor 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 LINECLR="$ESC[2K" # clear current line
BELOWCLR="$ESC[0J" # clear everything below BELOWCLR="$ESC[0J" # clear everything below
ALTBUFON="$ESC[?47h" # use the alternative screen buffer ALTBUFON="$ESC[?47h" # use the alternative screen buffer
@@ -117,24 +118,25 @@ amtogopher() { # args: AM line
} }
# AM entry clicker function # 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") readarray -d $'\t' -t fields < <(printf '%s' "$1")
local action="${fields[0]}" local action="${fields[0]}"
local desc="${fields[1]}" local desc="${fields[1]}"
local rhost="${fields[2]}" local rhost="${fields[2]}"
local rport="${fields[3]}" local rport="${fields[3]}"
local sel="${fields[4]}" 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 if [[ 'D' == "$action" ]]; then # download
local fname="${sel##*/}" # pure-bash version of basename local fname="${sel##*/}" # pure-bash version of basename
[[ -z "$fname" ]] && fname='dl.dat' # just make sure that it's not empty [[ -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" printf 'E\tDownloaded %s to %s\n' "$(amtogopher "$1")" "$BOPHER_DLDIR/$fname"
elif [[ 'I' == "$action" || 'M' == "$action" || 'P' == "$action" ]]; then # text content 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") readarray -t lines < <(gophetch "$rhost" "$rport" "$sel" "$input")
for line in "${lines[@]}"; do # iterate over every fetched line for line in "${lines[@]}"; do # iterate over every fetched line
if [[ 'P' == "$action" ]]; then # generate a plaintext AM entry 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] amload() { # args: AM line[, forcedl]
CURRENTAM="$1" # update current AM value CURRENTAM="$1" # update current AM value
printf '%b' "${LINECLR}Loading..." printf '%b' "${LINECLR}Loading..."
[[ ! -z "$2" ]] && CURRENTAM="D${CURRENTAM:1}" # modify CURRENTAM first char to the download type readarray -t SCREENBUF < <(amclick "$CURRENTAM" "$2") # populate screen buffer by loading the resource from the AM entry
readarray -t SCREENBUF < <(amclick "$CURRENTAM") # populate screen buffer by loading the resource from the AM entry
NAVIGABLES=() # reset the navigable indexes NAVIGABLES=() # reset the navigable indexes
CURLINKINDEX=0 # reset the link number CURLINKINDEX=0 # reset the link number
CURSCROLLPOS=0 # reset the scrolling position CURSCROLLPOS=0 # reset the scrolling position