Skip to content

Commit e3ec650

Browse files
committed
Fix errors with highlighting on macOS
* Source term-background.sh only if highlighting is enabled. BashSupport-Pro/bashsupport-pro#66 * Add safe fallback values in case parameters are not defined. BashSupport-Pro/bashsupport-pro#66
1 parent 4204dd4 commit e3ec650

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

init/opts.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ _Dbg_parse_options() {
129129

130130
typeset -i _Dbg_o_quiet=0
131131
typeset -i _Dbg_o_version=0
132+
typeset -i _Dbg_highlight_enabled=1
132133

133134
while getopts_long A:Bc:x:hL:nqTt:Yy:VX opt \
134135
annotate required_argument \
@@ -176,10 +177,12 @@ _Dbg_parse_options() {
176177

177178
if (( ! _Dbg_have_working_pygmentize )) ; then
178179
printf "Can't run pygmentize. --highlight forced off" >&2
180+
_Dbg_highlight_enabled=0
179181
_Dbg_set_highlight=''
180182
fi
181183
;;
182184
no-highlight )
185+
_Dbg_highlight_enabled=0
183186
_Dbg_set_highlight='' ;;
184187
init-file )
185188
set -x
@@ -249,25 +252,24 @@ welcome to change it and/or distribute copies of it under certain conditions.
249252
fi
250253
unset _Dbg_o_annotate _Dbg_o_version _Dbg_o_quiet
251254
_Dbg_script_args=("$@")
252-
}
253255

254-
if (( _Dbg_have_working_pygmentize )) && [[ -z "$_Dbg_set_highlight" ]] ; then
255-
# Honor DARK_BG if already set. If not set, set it.
256-
if [[ -z "$DARK_BG" ]] ; then
257-
. "${_Dbg_libdir}/init/term-background.sh" >/dev/null
258-
fi
256+
if (( _Dbg_have_working_pygmentize )) && (( _Dbg_highlight_enabled )) && [[ -z "$_Dbg_set_highlight" ]] ; then
257+
# Honor DARK_BG if already set. If not set, set it.
258+
if [[ -z "$DARK_BG" ]] ; then
259+
. "${_Dbg_libdir}/init/term-background.sh" >/dev/null
260+
fi
259261

260-
# DARK_BG is now either 0 or 1.
261-
# Set _Dbg_set_highlight based on DARK_BG
262-
# Note however that options processing has one more chance to
263-
# change _Dbg_set_highlight
264-
if (( $DARK_BG )); then
265-
_Dbg_set_highlight="dark"
266-
else
267-
_Dbg_set_highlight="light"
262+
# DARK_BG is now either 0 or 1.
263+
# Set _Dbg_set_highlight based on DARK_BG
264+
# Note however that options processing has one more chance to
265+
# change _Dbg_set_highlight
266+
if (( $DARK_BG )); then
267+
_Dbg_set_highlight="dark"
268+
else
269+
_Dbg_set_highlight="light"
270+
fi
268271
fi
269-
fi
270-
272+
}
271273

272274
# Stand-alone Testing.
273275
if [[ -n "$_Dbg_dbg_opts_test" ]] ; then

init/term-background.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ get_default_bg() {
5959
# On return, variable is_dark_bg is set
6060
is_dark_rgb() {
6161
typeset r g b
62-
r=$1; g=$2; b=$3
62+
r=${1:-FF}; g=${2:-FF}; b=${3:-FF}
6363
if (( (16#$r + 16#$g + 16#$b) < $TERMINAL_COLOR_MIDPOINT )) ; then
6464
is_dark_bg=1
6565
else

0 commit comments

Comments
 (0)