Skip to content

Commit e4e784f

Browse files
author
Chad Juliano
committed
Adding HSL colors to credits.
1 parent 1ff5630 commit e4e784f

File tree

11 files changed

+388
-245
lines changed

11 files changed

+388
-245
lines changed

src/biw-main.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
#
66
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
77
# reserved. See LICENSE.
8+
#
9+
# File: biw-main.sh
10+
# Description: Top-level script for panel menus.
811
##
912

1013
# generate errors if unset vars are used.
1114
set -o nounset
1215

1316
source ${BIW_HOME}/biw-term-csi.sh
1417
source ${BIW_HOME}/biw-term-sgr.sh
18+
source ${BIW_HOME}/biw-term-hsl.sh
1519
source ${BIW_HOME}/biw-theme.sh
16-
source ${BIW_HOME}/biw-vmenu.sh
17-
source ${BIW_HOME}/biw-hmenu.sh
18-
source ${BIW_HOME}/biw-credits.sh
20+
source ${BIW_HOME}/biw-panel-vmenu.sh
21+
source ${BIW_HOME}/biw-panel-hmenu.sh
22+
source ${BIW_HOME}/biw-panel-credits.sh
1923

24+
declare -r BIW_VERSION=0.9
2025
declare -ri BIW_ENABLE_DEBUG=0
2126

2227
# global widget params
2328
declare -ri BIW_MARGIN=10
24-
declare -ri BIW_PANEL_HEIGHT=9
29+
declare -ri BIW_PANEL_HEIGHT=10
2530
declare -ri BIW_PANEL_WIDTH=50
2631

2732
# max values to load for history and file lists
@@ -309,11 +314,9 @@ function fn_biw_panic()
309314
local _fail_line=${BASH_LINENO[0]}
310315
local _command=$BASH_COMMAND
311316

312-
# show cursor
317+
# show and restore cursor
313318
fn_csi_op $CSI_OP_CURSOR_SHOW
314-
315-
# restore default colors
316-
fn_sgr_set $SGR_ATTR_DEFAULT
319+
fn_csi_op $CSI_OP_CURSOR_RESTORE
317320

318321
echo
319322
echo "PANIC Failure at: "

src/biw-credits.sh renamed to src/biw-panel-credits.sh

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
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

2730
declare -a cred_color_map
2831
declare -i cred_color_map_size
32+
declare -i cred_color_use_216=0
2933
declare -a cred_alpha_map
3034

3135
function 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

78169
function 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

304381
function 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

315392
function 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

src/biw-hmenu.sh renamed to src/biw-panel-hmenu.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#
55
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
66
# reserved. See LICENSE.
7+
#
8+
# File: biw-panel-hmenu.sh
9+
# Description: Panel for horizontal menu.
710
##
811

912
# Layout
@@ -109,7 +112,7 @@ function fn_hmenu_redraw()
109112

110113
fn_sgr_seq_start
111114

112-
fn_theme_set_bg_attr $TATTR_BG_INACTIVE
115+
fn_theme_set_attr $TATTR_BG_INACTIVE
113116
fn_sgr_set $SGR_ATTR_UNDERLINE
114117
fn_sgr_print "$_r_pad"
115118
fn_sgr_set $SGR_ATTR_DEFAULT

src/biw-vmenu.sh renamed to src/biw-panel-vmenu.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#
55
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
66
# reserved. See LICENSE.
7+
#
8+
# File: biw-panel-vmenu.sh
9+
# Description: Display a scrollable vertical menu.
710
##
811

912
# placeholder for empty data set

src/biw-bind.sh renamed to src/biw-setup.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
#
55
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
66
# reserved. See LICENSE.
7+
#
8+
# File: biw-setup.sh
9+
# Description: Setup script to be added to .bashrc.
710
##
811

9-
function fn_biw_init()
10-
{
11-
fn_check_interactive
12-
13-
fn_biw_set_env
14-
15-
# load keyboard codes
16-
source ${BIW_HOME}/biw-term-csi.sh
17-
}
18-
19-
function fn_choose_bind()
12+
function fn_biw_setup_bind()
2013
{
2114
local -r _bind_key=$1
2215

@@ -25,11 +18,11 @@ function fn_choose_bind()
2518
local -r bind_int_char=$'"\201"'
2619
local -r bind_esc_char="\"\e${_bind_key}\""
2720

28-
bind -x ${bind_int_char}:fn_choose_show
21+
bind -x ${bind_int_char}:fn_biw_setup_show
2922
bind ${bind_esc_char}:${bind_int_char}
3023
}
3124

32-
function fn_choose_show()
25+
function fn_biw_setup_show()
3326
{
3427
if ! ${BIW_HOME}/biw-main.sh
3528
then
@@ -42,17 +35,14 @@ function fn_choose_show()
4235
rm $BIW_CH_RES_FILE
4336
}
4437

45-
function fn_check_interactive()
38+
function fn_biw_setup_env()
4639
{
4740
if [[ ! "$-" =~ "i" ]]
4841
then
4942
echo "ERROR: This script must be sourced and not executed."
5043
exit 1
5144
fi
52-
}
5345

54-
function fn_biw_set_env()
55-
{
5646
# file where history result will be saved
5747
export BIW_CH_RES_FILE=$HOME/.biw_selection
5848

@@ -72,8 +62,14 @@ function fn_biw_set_env()
7262
export BIW_HOME=$_script_dir
7363
}
7464

75-
# Activate bindings
76-
fn_biw_init
65+
# load env vars
66+
fn_biw_setup_env
67+
68+
# load keyboard codes
69+
if ! source ${BIW_HOME}/biw-term-csi.sh
70+
then
71+
return 1
72+
fi
7773

7874
# set bind key here
79-
fn_choose_bind $CSI_KEY_DOWN
75+
fn_biw_setup_bind $CSI_KEY_DOWN

src/biw-term-csi.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#
55
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
66
# reserved. See LICENSE.
7+
#
8+
# File: biw-term-csi.sh
9+
# Description: Send terminal control CSI sequences to manipulate the cursor.
710
##
811

912
# CSI op codes used with fn_csi_op

0 commit comments

Comments
 (0)