Skip to content

Commit 61b9422

Browse files
author
Chad Juliano
committed
Adding fast scroll to vmenu.
1 parent be3b588 commit 61b9422

File tree

8 files changed

+415
-297
lines changed

8 files changed

+415
-297
lines changed

src/biw-main.sh

100644100755
Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ source ${BIW_HOME}/biw-panel-credits.sh
2323

2424
declare -r BIW_VERSION=0.9
2525

26+
# debug only
27+
declare -i BIW_DEBUG_ENABLE=1
28+
declare -i BIW_DEBUG_SEQ=0
29+
declare BIW_DEBUG_MSG=''
30+
2631
# global widget params
2732
declare -ri BIW_MARGIN=10
28-
declare -ri BIW_PANEL_HEIGHT=12
29-
declare -ri BIW_PANEL_WIDTH=50
33+
declare -ri BIW_PANEL_HEIGHT=20
34+
declare -ri BIW_PANEL_WIDTH=60
3035

3136
# max values to load for history and file lists
32-
declare -ri BIW_VALUES_MAX=30
37+
declare -ri BIW_VALUES_MAX=50
3338

3439
declare -ri BIW_ACT_IGNORED=1
35-
declare -ri BIW_ACT_HANDLED=0
40+
declare -ri BIW_ACT_CHANGED=0
3641

3742
declare -r BIW_OC_ANIMATE_DELAY=0.015
3843

@@ -42,6 +47,9 @@ declare -r BIW_MENU_COMP="File"
4247
declare -r BIW_MENU_THEME="Theme"
4348
declare -r BIW_MENU_CREDITS="Credits"
4449

50+
# cached position of the curor after restore
51+
declare -i biw_cache_row_pos
52+
4553
function fn_biw_main()
4654
{
4755
# truncate result file
@@ -59,7 +67,8 @@ function fn_biw_main()
5967
fn_biw_show
6068

6169
# get result from index
62-
local _result=$(fn_vmenu_get_current_val)
70+
local _result
71+
fn_vmenu_get_current_val "_result"
6372

6473
# save to temporary file
6574
echo $_result > $BIW_CH_RES_FILE
@@ -74,7 +83,7 @@ function fn_biw_show()
7483

7584
while [ 1 ]
7685
do
77-
local _menu_val=$(fn_hmenu_get_current_val)
86+
fn_hmenu_get_current_val "_menu_val"
7887

7988
case $_menu_val in
8089
$BIW_MENU_HISTORY)
@@ -103,7 +112,7 @@ function fn_biw_show()
103112

104113
function fn_biw_process_key()
105114
{
106-
local _result_key=$1
115+
local _key_ref=$1
107116
local _timeout=${2:-''}
108117

109118
# don't print debug if we are animating something
@@ -112,21 +121,22 @@ function fn_biw_process_key()
112121
fn_biw_debug_print
113122
fi
114123

115-
fn_csi_read_key $_result_key $_timeout
116-
if [ $? != 0 ]
124+
if ! fn_csi_read_key $_key_ref $_timeout
117125
then
118126
# got timeout
119127
return 0
120128
fi
121129

122-
fn_hmenu_actions "${!_result_key}"
123-
if [ $? == $BIW_ACT_HANDLED ]
130+
fn_biw_debug_msg "_key=<%s>" "${!_key_ref}"
131+
132+
fn_hmenu_actions "${!_key_ref}"
133+
if [ $? == $BIW_ACT_CHANGED ]
124134
then
125135
# hmenu was changed so panel is being switched
126136
# return 1 so the controller will exit
127137
return 1
128138
fi
129-
139+
130140
# return 0 so the loop will continue
131141
return 0
132142
}
@@ -179,7 +189,7 @@ function fn_biw_list_controller()
179189
do
180190
fn_vmenu_actions "$_key"
181191

182-
if [ "$_key" == $CSI_KEY_EOL ]
192+
if [ "$_key" == $CSI_KEY_ENTER ]
183193
then
184194
# we got the enter key so close the menu
185195
return 1
@@ -200,16 +210,16 @@ function fn_biw_theme_controller()
200210
while fn_biw_process_key _key
201211
do
202212
fn_vmenu_actions "$_key"
203-
if [ $? == $BIW_ACT_HANDLED ]
213+
if [ $? == $BIW_ACT_CHANGED ]
204214
then
205215
# use the vmenu index to determine the selected theme
206-
fn_theme_set_idx_active $vmenu_idx_active
216+
fn_theme_set_idx_active $vmenu_idx_selected
207217
fn_hmenu_redraw
208218
fn_vmenu_redraw
209219
fi
210220

211221
case "$_key" in
212-
$CSI_KEY_EOL)
222+
$CSI_KEY_ENTER)
213223
# Save selected Theme
214224
fn_theme_save
215225

@@ -261,8 +271,32 @@ function fn_biw_open()
261271
# hide the cursor to eliminate flicker
262272
fn_csi_op $CSI_OP_CURSOR_HIDE
263273

274+
# get the current position of the cursor
275+
fn_csi_get_row_pos 'biw_cache_row_pos'
276+
277+
# scroll the screen to make space.
278+
fn_biw_scroll_open
279+
264280
# save the cursor for a "home position"
265281
fn_csi_op $CSI_OP_CURSOR_SAVE
282+
}
283+
284+
function fn_biw_scroll_open()
285+
{
286+
local -i _move_lines=$((biw_cache_row_pos - BIW_PANEL_HEIGHT - 1))
287+
#echo "biw_cache_row_pos: $biw_cache_row_pos"
288+
#exit
289+
290+
# if we are too close to the top of the screen then we need
291+
# to move down instead of scroll up.
292+
if((_move_lines < 0))
293+
then
294+
fn_csi_op $CSI_OP_ROW_DOWN $BIW_PANEL_HEIGHT
295+
296+
# update cursor position
297+
fn_csi_get_row_pos 'biw_cache_row_pos'
298+
return
299+
fi
266300

267301
# animate open
268302
for((_line_idx = 0; _line_idx < BIW_PANEL_HEIGHT; _line_idx++))
@@ -329,17 +363,14 @@ function fn_biw_panic()
329363

330364
echo "Call stack:"
331365
local _frame=0
332-
while caller $_frame; do
333-
((_frame++));
366+
while caller $_frame
367+
do
368+
((_frame++))
334369
done
335370

336371
exit 1
337372
}
338373

339-
declare -i BIW_DEBUG_ENABLE=0
340-
declare -i BIW_DEBUG_SEQ=0
341-
declare BIW_DEBUG_MSG=''
342-
343374
fn_biw_debug_print()
344375
{
345376
if((BIW_DEBUG_ENABLE <= 0))
@@ -350,7 +381,7 @@ fn_biw_debug_print()
350381
fn_csi_op $CSI_OP_CURSOR_RESTORE
351382
fn_csi_op $CSI_OP_ROW_ERASE
352383

353-
printf "DEBUG(%s): %s" $BIW_DEBUG_SEQ "$BIW_DEBUG_MSG"
384+
printf 'DEBUG(%03d): %s' $BIW_DEBUG_SEQ "${BIW_DEBUG_MSG:-<none>}"
354385

355386
BIW_DEBUG_MSG=''
356387
((BIW_DEBUG_SEQ++))
@@ -363,7 +394,7 @@ fn_biw_debug_msg()
363394
return
364395
fi
365396

366-
local _pattern="${1:-<no message>}"
397+
local _pattern="${1:-<empty>}"
367398
shift
368399
printf -v BIW_DEBUG_MSG "%s: ${_pattern}" ${FUNCNAME[1]} "$@"
369400
}

src/biw-panel-credits.sh

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ function fn_cred_show()
5959
fn_biw_debug_print
6060

6161
fn_cred_print_data
62+
local -i _result=$?
63+
64+
fn_biw_debug_msg "result: %d" $_result
6265

6366
# if animation was canceled then we get a non-zero status
64-
return $?
67+
return $_result
6568
}
6669

6770
function fn_cred_load_data()
@@ -173,12 +176,12 @@ function fn_cred_print_data()
173176
local -i _line_idx
174177
local -i _persist_cursor=0
175178

176-
for((_line_idx = 0; _line_idx < cred_canvas_height; _line_idx++))
179+
for((_line_idx = 0; _line_idx < cred_line_data_size; _line_idx++))
177180
do
178181
local _line_val="${cred_line_data[_line_idx]:-}"
179182
fn_cred_canvas_set_cursor $_line_idx 0
180183

181-
if((_line_idx == (cred_canvas_height - 1)))
184+
if((_line_idx == (cred_line_data_size - 1)))
182185
then
183186
_persist_cursor=1
184187
fi
@@ -423,45 +426,25 @@ function fn_cred_blank_panel()
423426
then
424427
fn_cred_blank_line
425428
else
426-
fn_cred_draw_bottom
429+
fn_cred_bottom_line
427430
fi
428431
fn_sgr_seq_flush
429432
done
430433
}
431434

432435
function fn_cred_blank_line()
433436
{
434-
local _line_val
435-
fn_cred_repeat_chars "_line_val" $cred_canvas_width
436-
fn_sgr_print $CSI_CHAR_LINE_VERT
437+
local _line_val=""
438+
fn_sgr_pad_string "_line_val" $cred_canvas_width
439+
fn_sgr_graphic_print $SGI_CHAR_LINE_VERT
437440
fn_sgr_print "$_line_val"
438-
fn_sgr_print $CSI_CHAR_LINE_VERT
441+
fn_sgr_graphic_print $SGI_CHAR_LINE_VERT
439442
}
440443

441-
function fn_cred_draw_bottom()
444+
function fn_cred_bottom_line()
442445
{
443-
local _dsc_start=$'\e(0'
444-
local _dsc_horiz_line=$'\x71'
445-
local _dsc_end=$'\e(B'
446-
447446
# draw bottom box
448-
fn_sgr_print $CSI_CHAR_LINE_BL
449-
fn_sgr_print $_dsc_start
450-
451-
local _bottom_line
452-
fn_cred_repeat_chars "_bottom_line" $cred_canvas_width $_dsc_horiz_line
453-
fn_sgr_print $_bottom_line
454-
455-
fn_sgr_print $CSI_CHAR_LINE_BR
456-
fn_sgr_print $_dsc_end
457-
}
458-
459-
function fn_cred_repeat_chars()
460-
{
461-
local _var_name=$1
462-
local -i _pad_width=$2
463-
local _pad_char=${3:- }
464-
465-
printf -v $_var_name '%*s' $_pad_width
466-
printf -v $_var_name "${!_var_name// /${_pad_char}}"
447+
fn_sgr_graphic_print $SGI_CHAR_LINE_BL
448+
fn_sgr_print_h_line $cred_canvas_width
449+
fn_sgr_graphic_print $SGI_CHAR_LINE_BR
467450
}

0 commit comments

Comments
 (0)