added: pagination for help and options windows on lower sizes, added: option to turn off gradient color in process list

pull/85/head
aristocratos 2020-04-30 18:01:13 +02:00
parent 49e03d0893
commit 72103c0e3b
1 changed files with 59 additions and 25 deletions

84
bashtop
View File

@ -101,6 +101,9 @@ custom_cpu_name=""
#* Enable error logging to "$HOME/.config/bashtop/error.log", "true" or "false"
error_logging="true"
#* Show color gradient in process list, "true" or "false"
proc_gradient="true"
aaz_config() { : ; } #! Do not remove this line!
#? End default variables-------------------------------------------------------------------------------->
@ -136,7 +139,8 @@ declare -A cpu mem swap proc net box theme
declare -a cpu_usage cpu_graph_a cpu_graph_b color_meter color_temp_graph color_cpu color_cpu_graph cpu_history color_mem_graph color_swap_graph
declare -a mem_history swap_history net_history_download net_history_upload mem_graph swap_graph proc_array download_graph upload_graph trace_array
declare resized=1 size_error clock tty_width tty_height hex="16#" cpu_p_box swap_on=1 draw_out esc_character boxes_out last_screen clock_out update_string
declare -a options_array=("color_theme" "update_ms" "proc_sorting" "check_temp" "draw_clock" "background_update" "error_logging" "custom_cpu_name")
declare -a options_array=("color_theme" "update_ms" "proc_sorting" "check_temp" "draw_clock" "background_update" "custom_cpu_name"
"proc_reversed" "proc_gradient" "error_logging")
declare -a save_array=("${options_array[@]}" "proc_reversed")
declare -a sorting=( "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu responsive" )
declare -a pid_history detail_graph detail_history detail_mem_history
@ -2261,14 +2265,16 @@ draw_processes() { #? Draw processes and values to screen
if [[ $argument == "now" ]]; then skip_process_draw=1; fi
fg_add_r=$(( (fg_r-(fg_r/6) )/height))
fg_add_g=$(( (fg_g-(fg_g/6) )/height))
fg_add_b=$(( (fg_b-(fg_b/6) )/height))
pid_add_r=$(( (pid_r-(pid_r/6) )/height))
pid_add_g=$(( (pid_g-(pid_g/6) )/height))
pid_add_b=$(( (pid_b-(pid_b/6) )/height))
if [[ $proc_gradient == true ]]; then
fg_add_r=$(( (fg_r-(fg_r/6) )/height))
fg_add_g=$(( (fg_g-(fg_g/6) )/height))
fg_add_b=$(( (fg_b-(fg_b/6) )/height))
pid_add_r=$(( (pid_r-(pid_r/6) )/height))
pid_add_g=$(( (pid_g-(pid_g/6) )/height))
pid_add_b=$(( (pid_b-(pid_b/6) )/height))
fi
unset proc_out
#* Details box
@ -2374,7 +2380,7 @@ draw_processes() { #? Draw processes and values to screen
if ((proc_start+proc[selected]>${#proc_array[@]})); then proc[selected]=$((${#proc_array[@]}-proc_start)); fi
if ((proc[selected]>1)); then
if [[ $proc_gradient == true ]] && ((proc[selected]>1)); then
fg_r="$(( fg_r-( fg_add_r*(proc[selected]-1) ) ))"
fg_g="$(( fg_g-( fg_add_g*(proc[selected]-1) ) ))"
fg_b="$(( fg_b-( fg_add_b*(proc[selected]-1) ) ))"
@ -2409,7 +2415,8 @@ draw_processes() { #? Draw processes and values to screen
((y++))
((current_num++))
if ((y>height-2)); then break; fi
if ((current_num<proc[selected]+1)); then
if [[ $proc_gradient == false ]]; then :
elif ((current_num<proc[selected]+1)); then
fg_step_r=$((fg_step_r-fg_add_r)); fg_step_g=$((fg_step_g-fg_add_g)); fg_step_b=$((fg_step_b-fg_add_b))
pid_step_r=$((pid_step_r-pid_add_r)); pid_step_g=$((pid_step_g-pid_add_g)); pid_step_b=$((pid_step_b-pid_add_b))
elif ((current_num>=proc[selected])); then
@ -2674,7 +2681,7 @@ menu_() { #? Shows the main menu overlay
}
help_() { #? Shows the help overlay
local tmp from_menu col line y i help_out help_pause redraw=1 wait_string
local help_key from_menu col line y i help_out help_pause redraw=1 wait_string pages page=1 height
local -a shortcuts descriptions
shortcuts=(
@ -2716,7 +2723,7 @@ help_() { #? Shows the help overlay
if [[ -n $pause_screen ]]; then from_menu=1; fi
until [[ -n $tmp ]]; do
until [[ -n $help_key ]]; do
#* Put program to sleep if caught ctrl-z
if ((sleepy==1)); then sleep_; redraw=1; fi
@ -2730,16 +2737,21 @@ help_() { #? Shows the help overlay
if [[ -n $redraw ]]; then
col=$((tty_width/2-36)); line=$((tty_height/2-4)); y=1
col=$((tty_width/2-36)); line=$((tty_height/2-4)); y=1; height=$((tty_height-2-line))
if ((${#shortcuts[@]}>height)); then pages=$(( (${#shortcuts[@]}/height)+1 )); else height=${#shortcuts[@]}; unset pages; fi
unset redraw help_out
draw_banner "$((tty_height/2-11))" help_out
print -d 1
create_box -v help_out -w 72 -h $((${#shortcuts[@]}+3)) -l $((line++)) -c $((col++)) -fill -lc ${theme[div_line]} -title "help"
create_box -v help_out -w 72 -h $((height+3)) -l $((line++)) -c $((col++)) -fill -lc ${theme[div_line]} -title "help"
if [[ -n $pages ]]; then
print -v help_out -m $((line-1)) $((col+72-17)) -rs -fg ${theme[div_line]} -t "┤" -fg ${theme[hi_fg]} -b -t "" -fg ${theme[title]} -t " page ${page}/${pages} " -fg ${theme[hi_fg]} -t "" -rs -fg ${theme[div_line]} -t "├"
fi
((++col))
print -v help_out -r 1 -fg ${theme[title]} -b -jl 20 -t "Key:" -jl 48 -t "Description:" -m $((line+y++)) $col
print -v help_out -m $line $col -fg ${theme[title]} -b -jl 20 -t "Key:" -jl 48 -t "Description:" -m $((line+y++)) $col
for((i=0;i<${#shortcuts[@]};i++)); do
for((i=(page-1)*height;i<page*height;i++)); do
print -v help_out -fg ${theme[main_fg]} -b -jl 20 -t "${shortcuts[i]}" -rs -fg ${theme[main_fg]} -jl 48 -t "${descriptions[i]}" -m $((line+y++)) $col
done
fi
@ -2755,7 +2767,15 @@ help_() { #? Shows the help overlay
elif ((time_left>0)); then printf -v wait_string ".%03d" "${time_left}"; time_left=0
else wait_string="0.001"; time_left=0; fi
get_key -v tmp -w "${wait_string}"
get_key -v help_key -w "${wait_string}"
if [[ -n $pages ]]; then
case $help_key in
right) if ((page<pages)); then ((page++)); else page=1; fi; redraw=1; unset help_key ;;
left) if ((page>1)); then ((page--)); else page=${pages}; fi; redraw=1; unset help_key ;;
esac
fi
if [[ $(stty size) != "$tty_height $tty_width" ]]; then resized; fi
if ((resized>0)); then
sleep 0.5
@ -2772,7 +2792,7 @@ help_() { #? Shows the help overlay
}
options_() { #? Shows the options overlay
local keypress from_menu col line y=1 i=1 options_out selected_int=0 ypos option_string options_misc option_value bg fg skipped start_t end_t left_t changed_cpu_name theme_int=0
local keypress from_menu col line y=1 i=1 options_out selected_int=0 ypos option_string options_misc option_value bg fg skipped start_t end_t left_t changed_cpu_name theme_int=0 page=1 pages height
local desc_col right left enter lr inp valid updated_ms local_rez redraw_misc=1 desc_pos desc_height options_pause updated_proc inputting inputting_value inputting_key file theme_check
#* Check theme folder for theme files
@ -2835,7 +2855,12 @@ options_() { #? Shows the options overlay
" "
"True or false."
"Takes effect after program restart.")
desc_proc_reversed=("Reverse sorting order."
" "
"True or false.")
desc_proc_gradient=("Show color gradient in process list."
" "
"True or False.")
if [[ -n $pause_screen ]]; then from_menu=1; fi
@ -2856,9 +2881,14 @@ options_() { #? Shows the options overlay
unset options_misc redraw_misc
col=$((tty_width/2-39))
line=$((tty_height/2-4))
height=$(( (tty_height-2-line)/2 ))
if ((${#options_array[@]}>height)); then pages=$(( (${#options_array[@]}/height)+1 )); else height=${#options_array[@]}; unset pages; fi
desc_col=$((col+30))
draw_banner "$((tty_height/2-11))" options_misc
create_box -v options_misc -w 29 -h $((${#options_array[@]}*2+2)) -l $line -c $((col-1)) -fill -lc ${theme[div_line]} -title "options"
create_box -v options_misc -w 29 -h $((height*2+2)) -l $line -c $((col-1)) -fill -lc ${theme[div_line]} -title "options"
if [[ -n $pages ]]; then
print -v options_misc -m $((line)) $((col+29-18)) -rs -fg ${theme[div_line]} -t "┤" -fg ${theme[hi_fg]} -b -t "p" -fg ${theme[title]} -t " page ${page}/${pages} " -fg ${theme[hi_fg]} -t "n" -rs -fg ${theme[div_line]} -t "├"
fi
fi
@ -2866,11 +2896,12 @@ options_() { #? Shows the options overlay
unset options_out desc_height lr inp valid
selected="${options_array[selected_int]}"
local -n selected_desc="desc_${selected}"
if [[ $background_update == false ]]; then desc_pos=$line; desc_height=$((${#options_array[@]}*2+2))
elif ((selected_int*2+${#selected_desc[@]}<${#options_array[@]}*2)); then desc_pos=$((line+selected_int*2))
else desc_pos=$((line+${#options_array[@]}*2-${#selected_desc[@]})); fi
if [[ $background_update == false ]]; then desc_pos=$line; desc_height=$((height*2+2))
elif (( (selected_int-( (page-1)*height) )*2+${#selected_desc[@]}<height*2 )); then desc_pos=$((line+(selected_int-( (page-1)*height) )*2))
else desc_pos=$((line+height*2-${#selected_desc[@]})); fi
create_box -v options_out -w 50 -h ${desc_height:-$((${#selected_desc[@]}+2))} -l $desc_pos -c $((desc_col-1)) -fill -lc ${theme[div_line]} -title "description"
for((i=0,ypos=1;i<${#options_array[@]};i++,ypos=ypos+2)); do
for((i=(page-1)*height,ypos=1;i<page*height;i++,ypos=ypos+2)); do
if [[ -z ${options_array[i]} ]]; then break; fi
option_string="${options_array[i]}"
if [[ -n $inputting && ${option_string} == "${selected}" ]]; then
if [[ ${#inputting_value} -gt 14 ]]; then option_value="${inputting_value:(-14)}_"
@ -2950,7 +2981,10 @@ options_() { #? Shows the options overlay
up|shift_tab) if ((selected_int>0)); then ((selected_int--)); else selected_int=$((${#options_array[@]}-1)); fi ;;
left|right) if [[ -n $lr && -z $inputting ]]; then valid=1; fi ;;
enter) if [[ -n $inp ]]; then valid=1; fi ;;
n) if ((page<pages)); then ((page++)); else page=1; selected_int=0; fi; redraw_misc=1; selected_int=$(( (page-1)*height )) ;;
p) if ((page>1)); then ((page--)); else page=${pages}; fi; redraw_misc=1; selected_int=$(( (page-1)*height )) ;;
esac
if (( selected_int<(page-1)*height | selected_int>=page*height )); then page=$(( (selected_int/height)+1 )); redraw_misc=1; fi
fi
if [[ ${selected} == "color_theme" && ${keypress} =~ left|right && ${#themes} -lt 2 ]]; then unset valid; fi
@ -2992,7 +3026,7 @@ options_() { #? Shows the options overlay
if [[ -z $inputting ]]; then inputting=1; inputting_value="${custom_cpu_name}"
else custom_cpu_name="${inputting_value}"; changed_cpu_name=1; unset inputting inputting_value; fi
;;
"check_temp"*|"error_logging"*|"background_update"*)
"check_temp"*|"error_logging"*|"background_update"*|"proc_reversed"*|"proc_gradient"*)
local -n selected_var=${selected}
if [[ ${selected_var} == "true" ]]; then
selected_var="false"