diff options
-rwxr-xr-x | bollux | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/bollux b/bollux index 5b41cda..06e5403 100755 --- a/bollux +++ b/bollux | |||
@@ -66,6 +66,7 @@ log() { | |||
66 | bollux() { | 66 | bollux() { |
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 | ||
309 | handle_response() { | 310 | handle_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 |
@@ -590,10 +589,16 @@ handle_keypress() { | |||
590 | run blastoff -u "$URL" | 589 | run blastoff -u "$URL" |
591 | ;; | 590 | ;; |
592 | 50) # [ - back in the history | 591 | 50) # [ - back in the history |
593 | run history_back | 592 | run history_back || { |
593 | sleep 0.5 | ||
594 | run blastoff "$BOLLUX_URL" | ||
595 | } | ||
594 | ;; | 596 | ;; |
595 | 51) # ] - forward in the history | 597 | 51) # ] - forward in the history |
596 | run history_forward | 598 | run history_forward || { |
599 | sleep 0.5 | ||
600 | run blastoff "$BOLLUX_URL" | ||
601 | } | ||
597 | ;; | 602 | ;; |
598 | 52) # r - re-request the current resource | 603 | 52) # r - re-request the current resource |
599 | run blastoff "$BOLLUX_URL" | 604 | run blastoff "$BOLLUX_URL" |
@@ -643,8 +648,37 @@ download() { | |||
643 | fi | 648 | fi |
644 | } | 649 | } |
645 | 650 | ||
646 | history_back() { log error "Not implemented."; } | 651 | history_init() { |
647 | history_forward() { log error "Not implemented."; } | 652 | declare -a HISTORY # history is kept in an array |
653 | HN=0 # position of history in the array | ||
654 | } | ||
655 | |||
656 | history_append() { # history_append URL | ||
657 | BOLLUX_URL="$1" | ||
658 | HISTORY[$HN]="$BOLLUX_URL" | ||
659 | log d "HN=$HN HISTORY: ${HISTORY[*]}" | ||
660 | ((HN += 1)) | ||
661 | } | ||
662 | |||
663 | history_back() { | ||
664 | log d "HN=$HN" | ||
665 | ((HN -= 2)) | ||
666 | if ((HN <= 0)); then | ||
667 | HN=0 | ||
668 | log e "Beginning of history." | ||
669 | return 1 | ||
670 | fi | ||
671 | blastoff "${HISTORY[$HN]}" | ||
672 | } | ||
673 | history_forward() { | ||
674 | log d "HN=$HN" | ||
675 | if ((HN >= ${#HISTORY[@]})); then | ||
676 | HN="${#HISTORY[@]}" | ||
677 | log e "End of history." | ||
678 | return 1 | ||
679 | fi | ||
680 | blastoff "${HISTORY[$HN]}" | ||
681 | } | ||
648 | 682 | ||
649 | if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | 683 | if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then |
650 | run bollux "$@" | 684 | run bollux "$@" |