Skip to content

Commit 25fd1cb

Browse files
author
Chad Juliano
committed
Adding bind config panel.
1 parent a9fbc85 commit 25fd1cb

File tree

11 files changed

+616
-399
lines changed

11 files changed

+616
-399
lines changed

src/biw-main.sh

Lines changed: 175 additions & 183 deletions
Large diffs are not rendered by default.

src/biw-panel-browse.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
##
3+
# BIW-TOOLS - Bash Inline Widget Tools
4+
# Copyright 2017 by Chad Juliano
5+
#
6+
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
7+
# reserved. See LICENSE.
8+
#
9+
# File: biw-panel-browse.sh
10+
# Description: File browser panel.
11+
##
12+
13+
# used so we can generate a relative path
14+
declare -r BIW_ORIG_PWD=$PWD
15+
16+
# max number of files to populate in file browser
17+
declare -ir BIW_BROWSE_MAX_FILES=50
18+
19+
function fn_ctl_browse_controller()
20+
{
21+
fn_ctl_browse_update
22+
23+
local _key
24+
while fn_utl_process_key _key
25+
do
26+
fn_vmenu_actions "$_key"
27+
if [ $? == $UTL_ACT_CHANGED ]
28+
then
29+
# vmenu handled the action so get next key
30+
continue
31+
fi
32+
33+
if [ "$_key" == $CSI_KEY_ENTER ]
34+
then
35+
# enter key was hit so update the screen
36+
fn_ctl_browse_select
37+
if [ $? == 1 ]
38+
then
39+
# exit app
40+
biw_terminate_app=1
41+
break
42+
fi
43+
fi
44+
done
45+
}
46+
47+
function fn_ctl_browse_select()
48+
{
49+
local _selected_file
50+
fn_vmenu_get_current_val '_selected_file'
51+
52+
if [ ! -d "$_selected_file" ]
53+
then
54+
# we got the enter key so close the menu
55+
local _rel_dir
56+
fn_utl_get_relpath '_rel_dir' "$BIW_ORIG_PWD" "$PWD"
57+
biw_selection_result="${_rel_dir}/${_selected_file}"
58+
return 1
59+
fi
60+
61+
if [ ! -x "$_selected_file" ]
62+
then
63+
fn_vmenu_set_message "ERROR: Directory permission denied."
64+
fn_vmenu_redraw
65+
return 0
66+
fi
67+
68+
# change real directories
69+
cd "$_selected_file" || fn_utl_die "Failed to change directory: $PWD"
70+
71+
# update panel with new directory
72+
fn_ctl_browse_update
73+
74+
return 0
75+
}
76+
77+
function fn_ctl_browse_update()
78+
{
79+
# fetch files
80+
local -a _ls_output
81+
local -r _ls_command="/bin/ls -a -p -1"
82+
83+
# read ls command results into an array
84+
mapfile -n$BIW_BROWSE_MAX_FILES -s1 -t _ls_output < <($_ls_command)
85+
86+
local -a _file_list=()
87+
local -a _file_list_ind=()
88+
local -a _dir_list=()
89+
local -a _dir_list_ind=()
90+
91+
local -i _file_idx
92+
local _file
93+
94+
for((_file_idx=0; _file_idx < ${#_ls_output[@]}; _file_idx++))
95+
do
96+
_file=${_ls_output[_file_idx]}
97+
98+
if [[ "$_file" =~ ^(.*)/$ ]]
99+
then
100+
_dir_list+=( "$_file" )
101+
102+
if [ ! -x "$_file" ]
103+
then
104+
_dir_list_ind+=( $BIW_CHAR_DBL_EXCL )
105+
elif [ "$_file" == '../' ]
106+
then
107+
_dir_list_ind+=( $BIW_CHAR_TRIANGLE_LT )
108+
else
109+
_dir_list_ind+=( $BIW_CHAR_TRIANGLE_RT )
110+
fi
111+
else
112+
_file_list+=( "$_file" )
113+
_file_list_ind+=( $BIW_CHAR_BULLET )
114+
fi
115+
done
116+
117+
local -a _dir_view=( "${_dir_list[@]}" )
118+
119+
if [ ${#_file_list[@]} != 0 ]
120+
then
121+
_dir_view+=( "${_file_list[@]}" )
122+
fi
123+
124+
local _rel_dir
125+
fn_utl_get_relpath '_rel_dir' "$BIW_ORIG_PWD" "$PWD"
126+
127+
fn_vmenu_init _dir_view[@]
128+
vmenu_ind_values=( "${_dir_list_ind[@]}" "${_file_list_ind[@]:-}" )
129+
fn_vmenu_set_message "PWD [${_rel_dir}]"
130+
131+
fn_vmenu_redraw
132+
}

src/biw-panel-credits.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ function fn_cred_print_line()
147147

148148
fn_sgr_seq_start
149149

150+
fn_theme_set_attr $THEME_SET_DEF_INACTIVE
151+
150152
# render sprites
151153
if((_text_active)); then
152154
if ! fn_cred_animate_text; then _text_active=0; fi
@@ -315,8 +317,6 @@ function fn_cred_canvas_set_cursor()
315317
fn_utl_set_cursor_pos \
316318
$((cred_canvas_row_pos + _row_pos)) \
317319
$((cred_canvas_col_pos + _col_pos))
318-
319-
fn_theme_set_attr $THEME_SET_DEF_INACTIVE
320320
}
321321

322322
function fn_cred_blank_panel()

src/biw-panel-vmenu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function fn_vmenu_fast_scroll()
169169
# draw the row to be scrolled to update the selection color
170170
fn_vmenu_draw_row $((vmenu_idx_selected - _direction)) $_direction
171171

172-
fn_csi_scroll_region $vmenu_height $_direction
172+
fn_csi_scroll_region $vmenu_row_pos $vmenu_height $_direction
173173

174174
((vmenu_idx_panel_top += _direction))
175175
((vmenu_idx_panel_end += _direction))

src/biw-settings.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
##
2+
# BIW-TOOLS - Bash Inline Widget Tools
3+
# Copyright 2017 by Chad Juliano
4+
#
5+
# Licensed under GNU Lesser General Public License v3.0 only. Some rights
6+
# reserved. See LICENSE.
7+
#
8+
# File: biw-settings.sh
9+
# Description: Configuration settings load/save.
10+
##
11+
12+
13+
# file for persisting theme
14+
declare -r BIW_SETTINGS_FILE=$HOME/.biw_settings
15+
16+
# file to store selection result
17+
readonly BIW_RESULT_FILE=$HOME/.biw_selection
18+
19+
# file used to pass back updates to the key binding
20+
readonly BIW_BIND_UPDATE_FILE=$HOME/.biw_bind_update
21+
22+
# array with settings parameters
23+
declare -A biw_settings_params=()
24+
25+
declare -r BIW_BIND_PARAM_NAME='bind-key-code'
26+
27+
# default key set to CSI_KEY_DOWN
28+
declare -r BIW_DEFAULT_BIND_KEY='[6'
29+
30+
function fn_settings_get_param()
31+
{
32+
local _param_name=$1
33+
local _param_ref=$2
34+
local _param_default=${3:-}
35+
36+
if [ ${#biw_settings_params[@]} == 0 ] && ! fn_settings_load
37+
then
38+
printf -v $_param_ref '%s' "$_param_default"
39+
return 1
40+
fi
41+
42+
local _param_val=${biw_settings_params[$_param_name]:-}
43+
if [ -z "$_param_val" ]
44+
then
45+
printf -v $_param_ref '%s' "$_param_default"
46+
return 1
47+
fi
48+
49+
printf -v $_param_ref '%s' "$_param_val"
50+
51+
return 0
52+
}
53+
54+
function fn_settings_set_param()
55+
{
56+
local _param_name=$1
57+
local _param_val=$2
58+
59+
biw_settings_params[$_param_name]="$_param_val"
60+
fn_settings_save
61+
}
62+
63+
function fn_settings_load()
64+
{
65+
biw_settings_params=()
66+
67+
if [ ! -r $BIW_SETTINGS_FILE ]
68+
then
69+
# nothing to do
70+
return 1
71+
fi
72+
73+
local _line
74+
while read -r _line
75+
do
76+
_key=${_line%%=*}
77+
_value="${_line##*=}"
78+
79+
if [ -z "$_key" ] || [ -z "$_value" ]
80+
then
81+
# skip this because we did not get a complete
82+
# key/val pair
83+
continue
84+
fi
85+
86+
biw_settings_params[$_key]="$_value"
87+
88+
done < $BIW_SETTINGS_FILE
89+
return 0
90+
}
91+
92+
function fn_settings_save()
93+
{
94+
local _key
95+
local _value
96+
97+
for _key in "${!biw_settings_params[@]}"
98+
do
99+
_value="${biw_settings_params[$_key]}"
100+
printf '%s=%s\n' $_key "$_value"
101+
done > $BIW_SETTINGS_FILE
102+
}
103+
104+
function fn_settings_get_hotkey()
105+
{
106+
local _result_ref=$1
107+
108+
fn_settings_get_param \
109+
$BIW_BIND_PARAM_NAME \
110+
$_result_ref \
111+
$BIW_DEFAULT_BIND_KEY
112+
}
113+
114+
function fn_settings_set_hotkey()
115+
{
116+
local _bind_key=$1
117+
118+
fn_settings_set_param \
119+
$BIW_BIND_PARAM_NAME \
120+
$_bind_key
121+
122+
echo "$_bind_key" > $BIW_BIND_UPDATE_FILE
123+
}

0 commit comments

Comments
 (0)