44#
55# Licensed under GNU Lesser General Public License v3.0 only. Some rights
66# reserved. See LICENSE.
7+ #
8+ # File: biw-panel-credits.sh
9+ # Description: Panel for animated credits.
710# #
811
912# constants
@@ -26,6 +29,7 @@ declare -i cred_canvas_height
2629
2730declare -a cred_color_map
2831declare -i cred_color_map_size
32+ declare -i cred_color_use_216=0
2933declare -a cred_alpha_map
3034
3135function fn_cred_show()
@@ -43,22 +47,54 @@ function fn_cred_show()
4347
4448 cred_alpha_map[cred_canvas_width]=0
4549
50+ # Use one of 3 color map types:
51+ fn_color_map_hsl_hue
52+ # fn_color_map_hsl_saturation
53+ # fn_color_map_simple
54+
55+ cred_color_map_size=${# cred_color_map[@]}
56+
4657 fn_cred_blank_panel
4758 fn_cred_load_data
48- fn_generate_color_map
59+
4960 fn_cred_print_data
5061
5162 # if animation was canceled then we get a non-zero status
5263 return $?
5364}
5465
55- function fn_generate_color_map()
66+ function fn_cred_load_data()
67+ {
68+ mapfile -n${cred_height} -t cred_line_data << -EOM
69+
70+ BIW - Bash Inline Widgets
71+ Version ${BIW_VERSION}
72+ Copyright 2017 by Chad Juliano
73+ 74+
75+ Find it at:
76+ https://github.com/chadj2/biw-tools
77+ EOM
78+
79+ cred_line_data_size=${# cred_line_data[*]}
80+ }
81+
82+ function fn_cred_set_color()
5683{
57- fn_theme_get_sgr $SGR_ATTR_FG $TATTR_TEXT
58- _sgr_text_color=$(( $? - SGR_ATTR_FG))
84+ local -i _sgr_color=$1
85+ if(( cred_color_use_216 ))
86+ then
87+ fn_sgr_color216_set $SGR_ATTR_FG $_sgr_color
88+ else
89+ fn_sgr_color16_set $SGR_ATTR_FG $_sgr_color
90+ fi
91+ }
5992
93+ function fn_color_map_simple()
94+ {
6095 cred_color_map=(
61- [1]=$_sgr_text_color
96+ [0]=0
97+ [1]=$SGR_COL_GREEN
6298 [2]=$SGR_COL_YELLOW
6399 [3]=$SGR_COL_YELLOW
64100 [4]=$SGR_COL_YELLOW
@@ -71,8 +107,63 @@ function fn_generate_color_map()
71107 [11]=$SGR_COL_YELLOW
72108 [12]=$SGR_COL_YELLOW
73109 )
110+ }
74111
75- cred_color_map_size=${# cred_color_map[@]}
112+ function fn_color_map_hsl_hue()
113+ {
114+ local -ir _hsl_sat=4
115+ local -ir _hsl_light=5
116+
117+ local -i _hsl_hue
118+ local -i _sgr_code
119+ local -i _map_idx=0
120+
121+ # 0 index is reserved
122+ cred_color_use_216=1
123+ cred_color_map=()
124+ cred_color_map[_map_idx++]=0
125+
126+ for(( _hsl_hue = HSL_HUE_GREEN; _hsl_hue <= HSL_HUE_BLUE; _hsl_hue++ ))
127+ do
128+ fn_hsl_get $_hsl_hue $_hsl_sat $_hsl_light
129+ _sgr_code=$?
130+
131+ for(( _hsl_sat_length = 0 ; _hsl_sat_length <= 1 ; _hsl_sat_length++ ))
132+ do
133+ cred_color_map[_map_idx++]=$_sgr_code
134+ done
135+ done
136+ }
137+
138+ function fn_color_map_hsl_saturation()
139+ {
140+ # move through the HSL cylinder on hue=12 (120 degrees)
141+ local -ir _max_hsl_hue=3
142+ local -ir _min_hsl_hue=-5
143+ local -ir _hsl_hue=12
144+ local -ir _hsl_light=5
145+
146+ local -i _hsl_sat
147+ local -i _sgr_code
148+ local -i _map_idx=0
149+
150+ # 0 index is reserved
151+ cred_color_use_216=1
152+ cred_color_map=()
153+ cred_color_map[_map_idx++]=0
154+
155+ # go through cylinder from the color indicated by hue to its inverse.
156+ # we go from partially saturated green (sat=3) because (sat=5) is too deep.
157+ for(( _hsl_sat = _max_hsl_hue; _hsl_sat >= _min_hsl_hue; _hsl_sat-- ))
158+ do
159+ fn_hsl_get $_hsl_hue $_hsl_sat $_hsl_light
160+ _sgr_code=$?
161+
162+ for(( _hsl_sat_length = 0 ; _hsl_sat_length <= 4 ; _hsl_sat_length++ ))
163+ do
164+ cred_color_map[_map_idx++]=$_sgr_code
165+ done
166+ done
76167}
77168
78169function fn_cred_print_data()
@@ -184,7 +275,7 @@ function fn_cred_animate_text()
184275 # add characters to the alpha map
185276 if(( _char_idx < _line_width))
186277 then
187- cred_alpha_map[_char_idx]=${ # cred_color_map[@]}
278+ cred_alpha_map[_char_idx]=$(( cred_color_map_size - 1 ))
188279 else
189280 return 1
190281 fi
@@ -205,7 +296,7 @@ function fn_cred_animate_cursor()
205296 fn_biw_set_col_pos $_cursor_pos
206297
207298 local _sgr_color=${cred_color_map[cred_color_map_size - 1]}
208- fn_sgr_set $(( SGR_ATTR_FG + _sgr_color))
299+ fn_cred_set_color $ _sgr_color
209300
210301 if(( _cursor_counter <= 0 ))
211302 then
@@ -271,7 +362,7 @@ function fn_cred_print_alpha()
271362 fi
272363
273364 _alpha_color=${cred_color_map[_alpha_val]}
274- fn_sgr_set $(( SGR_ATTR_FG + _alpha_color))
365+ fn_cred_set_color $ _alpha_color
275366
276367 _char_val=${_line_val: _alpha_idx: 1}
277368 fn_sgr_print " ${_char_val} "
@@ -286,20 +377,6 @@ function fn_cred_print_alpha()
286377 return 0
287378}
288379
289- function fn_cred_load_data()
290- {
291- mapfile -n${cred_height} -t cred_line_data << -EOM
292-
293- BIW - Bash Inline Widgets
294- Copyright 2017 by Chad Juliano
295- 296-
297- Find it at:
298- https://github.com/chadj2/biw-tools
299- EOM
300-
301- cred_line_data_size=${# cred_line_data[*]}
302- }
303380
304381function fn_cred_canvas_set_cursor()
305382{
@@ -309,7 +386,7 @@ function fn_cred_canvas_set_cursor()
309386 $(( cred_canvas_row_pos + _row_pos)) \
310387 $(( cred_canvas_col_pos + _col_pos))
311388
312- fn_theme_set_bg_attr $TATTR_BG_INACTIVE
389+ fn_theme_set_attr $TATTR_BG_INACTIVE
313390}
314391
315392function fn_cred_blank_panel()
@@ -322,7 +399,7 @@ function fn_cred_blank_panel()
322399 fn_biw_set_cursor_pos $_row_pos 0
323400
324401 fn_sgr_seq_start
325- fn_theme_set_bg_attr $TATTR_BG_INACTIVE
402+ fn_theme_set_attr $TATTR_BG_INACTIVE
326403
327404 if(( _line_idx < cred_canvas_height))
328405 then
0 commit comments