printf '%s\n' "$_"
}
+# cycle a variable, e.g. from 'one,two,three' => 'two,three,one'
+cycle_list() { # cycle_list LIST DELIM
+ local list="${!1}" delim="$2"
+ local first="${list%%${delim}*}"
+ local rest="${list#*${delim}}"
+ printf -v "$1" '%s%s%s' "${rest}" "${delim}" "${first}"
+}
+
+# determine the first element of a list, e.g. 'one,two,three' => 'one'
+first() { # first LIST DELIM
+ local list="${!1}" delim="$2"
+ printf '%s\n' "${list%%${delim}*}"
+}
+
log() { # log LEVEL MESSAGE
[[ "$BOLLUX_LOGLEVEL" == QUIET ]] && return
local fmt
: "${BOLLUX_PROTO:=gemini}" # default protocol
: "${BOLLUX_URL:=}" # start url
: "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message
+ : "${BOLLUX_PRE_DISPLAY:=pre,alt,both}" # how to view PRE blocks
## files
: "${BOLLUX_DATADIR:=${XDG_DATA_DIR:-$HOME/.local/share}/bollux}"
: "${BOLLUX_DOWNDIR:=.}" # where to save downloads
# generate a lesskey(1) file for custom keybinds
mklesskey() { # mklesskey FILENAME
- lesskey -o "$1" - <<-END
+ lesskey -o "$1" - <<-\END
#command
o quit 0 # 48 open a link
g quit 1 # 49 goto a url
] quit 3 # 51 forward
r quit 4 # 52 re-request / download
G quit 5 # 53 goto a url (pre-filled)
+ ` quit 6 # 54 cycle BOLLUX_PRE_DISPLAY and refresh
# other keybinds
- \\40 forw-screen-force
+ \40 forw-screen-force
h left-scroll
l right-scroll
? status # 'status' will show a little help thing.
log d "T_WIDTH=$T_WIDTH"
log d "WIDTH=$WIDTH"
+ log d "$BOLLUX_PRE_DISPLAY"
while IFS= read -r; do
case "$REPLY" in
'```'*)
+ PRE_LINE_FORCE=false
if $pre; then
pre=false
else
pre=true
fi
+ case "${BOLLUX_PRE_DISPLAY%%,*}" in
+ pre)
+ :
+ ;;
+ alt | both)
+ $pre && PRE_LINE_FORCE=true \
+ gemini_pre "${REPLY#\`\`\`}"
+ ;;
+ esac
continue
;;
'=>'*)
}
gemini_pre() {
- printf "\e[${C_SIGIL}m%${S_MARGIN}s " '```'
- printf "\e[${C_PRE}m%s${C_RESET}\n" "$1"
+ # Print preformatted text, dependent on $BOLLUX_PRE_DISPLAY and
+ # $PRE_LINE_FORCE
+ if [[ alt != "${BOLLUX_PRE_DISPLAY%%,*}" ]] || $PRE_LINE_FORCE; then
+ printf "\e[${C_SIGIL}m%${S_MARGIN}s " '```'
+ printf "\e[${C_PRE}m%s${C_RESET}\n" "$1"
+ fi
}
# wrap lines on words to WIDTH
run prompt -u GO
run blastoff -u "$REPLY"
;;
- *) # 54-57 -- still available for binding
+ 54) # ` - change alt-text visibility and refresh
+ run cycle_list BOLLUX_PRE_DISPLAY ,
+ run blastoff "$BOLLUX_URL"
+ ;;
+ 55) # 55-57 -- still available for binding
die "$?" "less(1) error"
;;
esac