about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xbollux52
1 files changed, 43 insertions, 9 deletions
diff --git a/bollux b/bollux index e0d37d2..9055b5d 100755 --- a/bollux +++ b/bollux
@@ -66,6 +66,7 @@ log() {
66bollux() { 66bollux() {
67 run bollux_config 67 run bollux_config
68 run bollux_args "$@" 68 run bollux_args "$@"
69 run history_init
69 70
70 if [[ ! "${BOLLUX_URL:+isset}" ]]; then 71 if [[ ! "${BOLLUX_URL:+isset}" ]]; then
71 run prompt GO BOLLUX_URL 72 run prompt GO BOLLUX_URL
@@ -307,7 +308,7 @@ request_url() {
307} 308}
308 309
309handle_response() { 310handle_response() {
310 local url="$1" code meta 311 local URL="$1" code meta
311 312
312 while read -r -d $'\r' hdr; do 313 while read -r -d $'\r' hdr; do
313 code="$(gawk '{print $1}' <<<"$hdr")" 314 code="$(gawk '{print $1}' <<<"$hdr")"
@@ -322,14 +323,14 @@ handle_response() {
322 case "$code" in 323 case "$code" in
323 1*) 324 1*)
324 REDIRECTS=0 325 REDIRECTS=0
325 BOLLUX_URL="$URL" 326 run history_append "$URL"
326 run prompt "$meta" QUERY 327 run prompt "$meta" QUERY
327 # shellcheck disable=2153 328 # shellcheck disable=2153
328 run blastoff "?$QUERY" 329 run blastoff "?$QUERY"
329 ;; 330 ;;
330 2*) 331 2*)
331 REDIRECTS=0 332 REDIRECTS=0
332 BOLLUX_URL="$URL" 333 run history_append "$URL"
333 run display "$meta" 334 run display "$meta"
334 ;; 335 ;;
335 3*) 336 3*)
@@ -337,7 +338,6 @@ handle_response() {
337 if ((REDIRECTS > BOLLUX_MAXREDIR)); then 338 if ((REDIRECTS > BOLLUX_MAXREDIR)); then
338 die $((100 + code)) "Too many redirects!" 339 die $((100 + code)) "Too many redirects!"
339 fi 340 fi
340 BOLLUX_URL="$URL"
341 run blastoff "$meta" 341 run blastoff "$meta"
342 ;; 342 ;;
343 4*) 343 4*)
@@ -368,7 +368,6 @@ display() {
368 mime="$(trim "${hdr[0],,}")" 368 mime="$(trim "${hdr[0],,}")"
369 for ((i = 1; i <= "${#hdr[@]}"; i++)); do 369 for ((i = 1; i <= "${#hdr[@]}"; i++)); do
370 h="$(trim "${hdr[$i]}")" 370 h="$(trim "${hdr[$i]}")"
371 log d "'$h'"
372 case "$h" in 371 case "$h" in
373 charset=*) charset="${h#charset=}" ;; 372 charset=*) charset="${h#charset=}" ;;
374 esac 373 esac
@@ -592,10 +591,16 @@ handle_keypress() {
592 run blastoff -u "$URL" 591 run blastoff -u "$URL"
593 ;; 592 ;;
594 50) # [ - back in the history 593 50) # [ - back in the history
595 run history_back 594 run history_back || {
595 sleep 0.5
596 run blastoff "$BOLLUX_URL"
597 }
596 ;; 598 ;;
597 51) # ] - forward in the history 599 51) # ] - forward in the history
598 run history_forward 600 run history_forward || {
601 sleep 0.5
602 run blastoff "$BOLLUX_URL"
603 }
599 ;; 604 ;;
600 52) # r - re-request the current resource 605 52) # r - re-request the current resource
601 run blastoff "$BOLLUX_URL" 606 run blastoff "$BOLLUX_URL"
@@ -645,8 +650,37 @@ download() {
645 fi 650 fi
646} 651}
647 652
648history_back() { log error "Not implemented."; } 653history_init() {
649history_forward() { log error "Not implemented."; } 654 declare -a HISTORY # history is kept in an array
655 HN=0 # position of history in the array
656}
657
658history_append() { # history_append URL
659 BOLLUX_URL="$1"
660 HISTORY[$HN]="$BOLLUX_URL"
661 log d "HN=$HN HISTORY: ${HISTORY[*]}"
662 ((HN += 1))
663}
664
665history_back() {
666 log d "HN=$HN"
667 ((HN -= 2))
668 if ((HN < 0)); then
669 HN=0
670 log e "Beginning of history."
671 return 1
672 fi
673 blastoff "${HISTORY[$HN]}"
674}
675history_forward() {
676 log d "HN=$HN"
677 if ((HN >= ${#HISTORY[@]})); then
678 HN="${#HISTORY[@]}"
679 log e "End of history."
680 return 1
681 fi
682 blastoff "${HISTORY[$HN]}"
683}
650 684
651if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then 685if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
652 run bollux "$@" 686 run bollux "$@"