Skip to content

Commit d1a74ee

Browse files
author
Chad Juliano
committed
Clean up theme code.
1 parent e4e784f commit d1a74ee

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

src/biw-theme.sh

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ function fn_theme_set_attr_default()
177177
local -i _is_active=$1
178178
if ((_is_active == 0))
179179
then
180+
#set -x
180181
fn_theme_set_attr $TATTR_BG_INACTIVE
182+
#exit
181183
else
182184
fn_theme_set_attr $TATTR_BG_ACTIVE
183185
fi
@@ -197,46 +199,61 @@ function fn_theme_set_attr_slider()
197199
function fn_theme_set_attr()
198200
{
199201
local -i _bg_attr_name=$1
200-
local -i _sgr_attr=$SGR_ATTR_DEFAULT
201-
202-
fn_theme_get_sgr $SGR_ATTR_BG $_bg_attr_name
203-
local -i _sgr_bg_color=$?
204202

205-
if ((_sgr_bg_color < TATTR_SGR_BASE))
203+
local -i _bg_sgr_nested=$((!sgr_buffer_active))
204+
205+
if((_bg_sgr_nested))
206206
then
207-
# this is a attribute and not a color
208-
_sgr_attr=$_sgr_bg_color
207+
fn_sgr_seq_start
208+
fi
209+
210+
fn_sgr_set $SGR_ATTR_DEFAULT
211+
212+
fn_theme_set_color $SGR_ATTR_BG $_bg_attr_name
213+
local -i _sgr_attr_bg=$?
209214

210-
# use the default background color
211-
fn_theme_get_sgr $SGR_ATTR_BG $TATTR_BG_INACTIVE
212-
_sgr_bg_color=$?
215+
if((_sgr_attr_bg))
216+
then
217+
# this is a attribute and not a color so set the background
218+
fn_theme_set_color $SGR_ATTR_BG $TATTR_BG_INACTIVE
219+
fn_sgr_set $_sgr_attr_bg
213220
fi
214221

215-
fn_theme_get_sgr $SGR_ATTR_FG $TATTR_TEXT
216-
local -i _sgr_fg_color=$?
222+
fn_theme_set_color $SGR_ATTR_FG $TATTR_TEXT
223+
local -i _sgr_attr_fg=$?
224+
225+
if((_sgr_attr_fg))
226+
then
227+
if((_sgr_attr_fg))
228+
then
229+
echo "ERROR: _sgr_attr_fg and _sgr_attr_bg can't both be set."
230+
fi
231+
fn_sgr_set $_sgr_attr_fg
232+
fi
217233

218-
# send triplet command
219-
fn_sgr_set "${_sgr_attr};${_sgr_fg_color};${_sgr_bg_color}"
234+
if((_bg_sgr_nested))
235+
then
236+
fn_sgr_seq_flush
237+
fi
220238
}
221239

222-
function fn_theme_get_sgr()
240+
function fn_theme_set_color()
223241
{
224-
local -i _sgr_type=$1
225-
local -i _attr_name=$2
242+
local -i _sgr_mode=$1
243+
local -i _theme_attr_name=$2
226244

227-
local -i _attr_val=${theme_active[$_attr_name]}
228-
local -i _sgr_code_result
245+
local -i _theme_attr_val=${theme_active[$_theme_attr_name]}
229246

230-
if ((_attr_val >= TATTR_SGR_BASE && _attr_val < SGR_ATTR_BRIGHT))
247+
if ((_theme_attr_val >= TATTR_SGR_BASE && _theme_attr_val < SGR_ATTR_BRIGHT))
231248
then
232-
# This is an attribute and not a color
233-
_sgr_code_result=$((_attr_val - TATTR_SGR_BASE))
234-
else
235-
# regular SGR color
236-
_sgr_code_result=$((_attr_val + _sgr_type))
249+
# This is an attribute and not a color so return the attribute
250+
local -i _sgr_attr=$((_theme_attr_val - TATTR_SGR_BASE))
251+
return $_sgr_attr
237252
fi
238253

239-
return $_sgr_code_result
254+
fn_sgr_color16_set $_sgr_mode $_theme_attr_val
255+
256+
return 0
240257
}
241258

242259
# always init theme

0 commit comments

Comments
 (0)