@@ -23,16 +23,21 @@ source ${BIW_HOME}/biw-panel-credits.sh
2323
2424declare -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
2732declare -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
3439declare -ri BIW_ACT_IGNORED=1
35- declare -ri BIW_ACT_HANDLED =0
40+ declare -ri BIW_ACT_CHANGED =0
3641
3742declare -r BIW_OC_ANIMATE_DELAY=0.015
3843
@@ -42,6 +47,9 @@ declare -r BIW_MENU_COMP="File"
4247declare -r BIW_MENU_THEME=" Theme"
4348declare -r BIW_MENU_CREDITS=" Credits"
4449
50+ # cached position of the curor after restore
51+ declare -i biw_cache_row_pos
52+
4553function 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
104113function 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-
343374fn_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}
0 commit comments