about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-02-26 20:37:51 -0600
committerCase Duckworth2021-02-26 20:37:51 -0600
commitc62c0f0d5348d4fe6b6b6911150c09ef455f669d (patch)
tree3f69c6e30f714936ed83e54db2522adfd41c2e9c
parentReword comment (diff)
downloadbollux-c62c0f0d5348d4fe6b6b6911150c09ef455f669d.tar.gz
bollux-c62c0f0d5348d4fe6b6b6911150c09ef455f669d.zip
Add BOLLUX_PRE_DISPLAY and functionality (fix #1)
Configuration option: BOLLUX_PRE_DISPLAY
- comma-separated list of following options: 'pre', 'alt', 'both'
- default: 'pre,alt,both'

Keybind: `
- when pressed, will cycle through the options in BOLLUX_PRE_DISPLAY

Full documentation coming in the next commit.
-rwxr-xr-xbollux45
1 files changed, 40 insertions, 5 deletions
diff --git a/bollux b/bollux index 07e12f0..df27c92 100755 --- a/bollux +++ b/bollux
@@ -50,6 +50,20 @@ trim_string() { # trim_string STRING
50 printf '%s\n' "$_" 50 printf '%s\n' "$_"
51} 51}
52 52
53# cycle a variable, e.g. from 'one,two,three' => 'two,three,one'
54cycle_list() { # cycle_list LIST DELIM
55 local list="${!1}" delim="$2"
56 local first="${list%%${delim}*}"
57 local rest="${list#*${delim}}"
58 printf -v "$1" '%s%s%s' "${rest}" "${delim}" "${first}"
59}
60
61# determine the first element of a list, e.g. 'one,two,three' => 'one'
62first() { # first LIST DELIM
63 local list="${!1}" delim="$2"
64 printf '%s\n' "${list%%${delim}*}"
65}
66
53log() { # log LEVEL MESSAGE 67log() { # log LEVEL MESSAGE
54 [[ "$BOLLUX_LOGLEVEL" == QUIET ]] && return 68 [[ "$BOLLUX_LOGLEVEL" == QUIET ]] && return
55 local fmt 69 local fmt
@@ -122,6 +136,7 @@ bollux_config() {
122 : "${BOLLUX_PROTO:=gemini}" # default protocol 136 : "${BOLLUX_PROTO:=gemini}" # default protocol
123 : "${BOLLUX_URL:=}" # start url 137 : "${BOLLUX_URL:=}" # start url
124 : "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message 138 : "${BOLLUX_BYEMSG:=See You Space Cowboy ...}" # bye message
139 : "${BOLLUX_PRE_DISPLAY:=pre,alt,both}" # how to view PRE blocks
125 ## files 140 ## files
126 : "${BOLLUX_DATADIR:=${XDG_DATA_DIR:-$HOME/.local/share}/bollux}" 141 : "${BOLLUX_DATADIR:=${XDG_DATA_DIR:-$HOME/.local/share}/bollux}"
127 : "${BOLLUX_DOWNDIR:=.}" # where to save downloads 142 : "${BOLLUX_DOWNDIR:=.}" # where to save downloads
@@ -720,7 +735,7 @@ less_prompt_escape() { # less_prompt_escape STRING
720 735
721# generate a lesskey(1) file for custom keybinds 736# generate a lesskey(1) file for custom keybinds
722mklesskey() { # mklesskey FILENAME 737mklesskey() { # mklesskey FILENAME
723 lesskey -o "$1" - <<-END 738 lesskey -o "$1" - <<-\END
724 #command 739 #command
725 o quit 0 # 48 open a link 740 o quit 0 # 48 open a link
726 g quit 1 # 49 goto a url 741 g quit 1 # 49 goto a url
@@ -728,8 +743,9 @@ mklesskey() { # mklesskey FILENAME
728 ] quit 3 # 51 forward 743 ] quit 3 # 51 forward
729 r quit 4 # 52 re-request / download 744 r quit 4 # 52 re-request / download
730 G quit 5 # 53 goto a url (pre-filled) 745 G quit 5 # 53 goto a url (pre-filled)
746 ` quit 6 # 54 cycle BOLLUX_PRE_DISPLAY and refresh
731 # other keybinds 747 # other keybinds
732 \\40 forw-screen-force 748 \40 forw-screen-force
733 h left-scroll 749 h left-scroll
734 l right-scroll 750 l right-scroll
735 ? status # 'status' will show a little help thing. 751 ? status # 'status' will show a little help thing.
@@ -767,15 +783,26 @@ typeset_gemini() {
767 783
768 log d "T_WIDTH=$T_WIDTH" 784 log d "T_WIDTH=$T_WIDTH"
769 log d "WIDTH=$WIDTH" 785 log d "WIDTH=$WIDTH"
786 log d "$BOLLUX_PRE_DISPLAY"
770 787
771 while IFS= read -r; do 788 while IFS= read -r; do
772 case "$REPLY" in 789 case "$REPLY" in
773 '```'*) 790 '```'*)
791 PRE_LINE_FORCE=false
774 if $pre; then 792 if $pre; then
775 pre=false 793 pre=false
776 else 794 else
777 pre=true 795 pre=true
778 fi 796 fi
797 case "${BOLLUX_PRE_DISPLAY%%,*}" in
798 pre)
799 :
800 ;;
801 alt | both)
802 $pre && PRE_LINE_FORCE=true \
803 gemini_pre "${REPLY#\`\`\`}"
804 ;;
805 esac
779 continue 806 continue
780 ;; 807 ;;
781 '=>'*) 808 '=>'*)
@@ -881,8 +908,12 @@ gemini_text() {
881} 908}
882 909
883gemini_pre() { 910gemini_pre() {
884 printf "\e[${C_SIGIL}m%${S_MARGIN}s " '```' 911 # Print preformatted text, dependent on $BOLLUX_PRE_DISPLAY and
885 printf "\e[${C_PRE}m%s${C_RESET}\n" "$1" 912 # $PRE_LINE_FORCE
913 if [[ alt != "${BOLLUX_PRE_DISPLAY%%,*}" ]] || $PRE_LINE_FORCE; then
914 printf "\e[${C_SIGIL}m%${S_MARGIN}s " '```'
915 printf "\e[${C_PRE}m%s${C_RESET}\n" "$1"
916 fi
886} 917}
887 918
888# wrap lines on words to WIDTH 919# wrap lines on words to WIDTH
@@ -976,7 +1007,11 @@ handle_keypress() { # handle_keypress CODE
976 run prompt -u GO 1007 run prompt -u GO
977 run blastoff -u "$REPLY" 1008 run blastoff -u "$REPLY"
978 ;; 1009 ;;
979 *) # 54-57 -- still available for binding 1010 54) # ` - change alt-text visibility and refresh
1011 run cycle_list BOLLUX_PRE_DISPLAY ,
1012 run blastoff "$BOLLUX_URL"
1013 ;;
1014 55) # 55-57 -- still available for binding
980 die "$?" "less(1) error" 1015 die "$?" "less(1) error"
981 ;; 1016 ;;
982 esac 1017 esac