about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xbollux66
1 files changed, 56 insertions, 10 deletions
diff --git a/bollux b/bollux index 079c83b..7711dd6 100755 --- a/bollux +++ b/bollux
@@ -289,13 +289,29 @@ handle() { # handle URL < RESPONSE
289} 289}
290 290
291# display the page 291# display the page
292display() { # display MIMETYPE < DOCUMENT 292display() { # display META < DOCUMENT
293 mimetype="$1" 293 case "$1" in
294 case "$mimetype" in 294 *\;*)
295 mime="$(cut -d\; -f1 <<<"$1" | trim)"
296 charset="$(cut -d\; -f2 <<<"$1" | trim)"
297 ;;
298 *) mime="$(trim <<<"$1")" ;;
299 esac
300 [ -z "$mime" ] && mime="text/gemini"
301 if [ -z "$charset" ]; then
302 charset="utf-8"
303 else
304 charset="${charset#*=}"
305 fi
306
307 log 5 "mime=$mime; charset=$charset"
308
309 case "$mime" in
310 text/gemini)
311 lfn | typeset_gemini | less -R
312 ;;
295 text/*) 313 text/*)
296 # normalize line endings to "\n" 314 lfn
297 # gawk 'BEGIN{RS=""}{gsub(/\r\n?/,"\n");print}'
298 cat
299 # TODO: use less with linking and stuff 315 # TODO: use less with linking and stuff
300 # less -R -p'^=>' +g 316 # less -R -p'^=>' +g
301 # lesskey: 317 # lesskey:
@@ -308,12 +324,42 @@ display() { # display MIMETYPE < DOCUMENT
308 # also look into the prompt, the filename, and input preprocessor 324 # also look into the prompt, the filename, and input preprocessor
309 # ($LESSOPEN, $LESSCLOSE) 325 # ($LESSOPEN, $LESSCLOSE)
310 ;; 326 ;;
311 *) 327 *) download "$URL" ;;
312 download "$URL"
313 ;;
314 esac 328 esac
315} 329}
316 330
331# normalize line endings to \n (LF)
332lfn() {
333 gawk 'BEGIN{RS="\n\n"}{gsub(/\r\n?/,"\n");print;print ""}'
334}
335
336# typeset text
337typeset_gemini() { # typeset_gemini < INPUT
338 gawk '
339 BEGIN { pre = 0 }
340 /^###/ { sub(/^#+[[:space:]]*/, "");
341 printf " \033[3m%s\033[0m\n", $0
342 next }
343 /^##/ { sub(/^#+[[:space:]]*/, "");
344 printf " \033[1m%s\033[0m\n", $0
345 next }
346 /^#/ { sub(/^#+[[:space:]]*/, "");
347 printf " \033[1;4m%s\033[0m\n", $0
348 next }
349 /^=>/ {
350 sub(/=>[[:space:]]*/, "")
351 url = $1; desc = ""
352 for (w=2;w<=NF;w++)
353 desc = desc (desc?" ":"") $w
354 printf " \033[1m[%s]\033[0m \033[4m%s\033[0m \033[36m%s\033[0m\n",
355 (++ln), desc, "(" url ")"
356 next }
357 # /^\*/ { sub(/\*[[:space:]]*/, ""); }
358 /```/ { pre = !pre; next }
359 { sub(/^/, " "); print }
360 '
361}
362
317download() { # download URL < FILE 363download() { # download URL < FILE
318 tn="$(mktemp)" 364 tn="$(mktemp)"
319 dd status=progress >"$tn" 365 dd status=progress >"$tn"
@@ -363,7 +409,7 @@ bollux_setup() {
363} 409}
364 410
365bollux_cleanup() { 411bollux_cleanup() {
366 echo 412 exit $?
367} 413}
368 414
369if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then 415if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then