Skip to content

Commit 52be06f

Browse files
committed
v0.8.0 added theme support, update checker and misc fixes
1 parent 28e1661 commit 52be06f

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

bashtop

+26-37
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ color_init_() { #? Check for theme file and set colors
324324
done
325325

326326
#* Set background color if set, otherwise use terminal default
327-
if [[ -n ${theme[main_bg]} ]]; then theme[main_bg]=";48;2;${theme[main_bg]// /;}"; fi
327+
if [[ -n ${theme[main_bg]} ]]; then theme[main_bg_dec]="${theme[main_bg]}"; theme[main_bg]=";48;2;${theme[main_bg]// /;}"; fi
328328

329329
#* Set colors from theme file if found, otherwise use default values
330330
theme[main_fg]="${theme[main_fg]:-$main_fg}"
@@ -973,16 +973,16 @@ create_graph() { #? Create a graph from an array of percentage values, usage;
973973

974974
#* Set up graph array print side numbers and lines
975975
print -v graph_array[0] -rs
976-
print -v graph_array[0] -m $((line+g_index[0])) ${col} ${normal_vals:+-jr 3 -fg ee -b -t "${side_num[0]}" -rs -fg 90 -t "${g_char[0]}"} -fg ${colors[100]}
976+
print -v graph_array[0] -m $((line+g_index[0])) ${col} ${normal_vals:+-jr 3 -fg ee -b -t "${side_num[0]}" -rs -fg ${theme[main_fg]} -t "${g_char[0]}"} -fg ${colors[100]}
977977
for((i=1;i<height;i++)); do
978-
print -v graph_array[i] -m $((line+g_index[i])) ${col} ${normal_vals:+-r 3 -fg 90 -t "${g_char[0]}"} -fg ${colors[$((100-i*100/height))]}
978+
print -v graph_array[i] -m $((line+g_index[i])) ${col} ${normal_vals:+-r 3 -fg ${theme[main_fg]} -t "${g_char[0]}"} -fg ${colors[$((100-i*100/height))]}
979979
done
980980

981981
if [[ -z $no_guide ]]; then width=$((width-5)); fi
982982

983983
graph_array[height]=""
984984
if [[ -z $no_guide ]]; then
985-
print -v graph_array[$height] -m $((line+g_index[(-1)])) ${col} -jr 3 -fg ee -b -t "${side_num[1]}" -rs -fg 90 -t "${g_char[1]}" -rp ${width} -t "${g_char[2]}"
985+
print -v graph_array[$height] -m $((line+g_index[(-1)])) ${col} -jr 3 -fg ee -b -t "${side_num[1]}" -rs -fg $[${theme[main_fg]}] -t "${g_char[1]}" -rp ${width} -t "${g_char[2]}"
986986
fi
987987

988988
#* If no color array was given, create a simple greyscale array
@@ -1948,11 +1948,11 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages
19481948
if ((resized>0)); then
19491949
local graph_a_size graph_b_size
19501950
graph_a_size=$((height/2)); graph_b_size=${graph_a_size}
1951+
19511952
if ((graph_a_size*2<height)); then ((graph_a_size++)); fi
1952-
# create_graph -o cpu_graph_a -d ${line} ${col} ${height} $((width-p_width-2)) -c color_cpu_graph cpu_history
19531953
create_graph -o cpu_graph_a -d ${line} ${col} ${graph_a_size} $((width-p_width-2)) -c color_cpu_graph -n cpu_history
19541954
create_graph -o cpu_graph_b -d $((line+graph_a_size)) ${col} ${graph_b_size} $((width-p_width-2)) -c color_cpu_graph -i -n cpu_history
1955-
# threads=${box[testing]} #! For testing, remove <--------------
1955+
19561956
for((i=1;i<=threads;i++)); do
19571957
create_mini_graph -o "cpu_core_graph_$i" -w 10 -c color_cpu_graph "cpu_core_history_$i"
19581958
done
@@ -2017,17 +2017,17 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages
20172017
elif ((p_width>24+temp_width & i>=p_height-2)); then pt_line=$((p_line+i-y*2)); pt_col=$((p_col+24+temp_width))
20182018
else y=$i; fi
20192019

2020-
print -v cpu_out_var -m $((pt_line+y)) $pt_col -rs -fg $p_normal_color -jl 7 -t "$name" -fg 30 "⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀" -l 10 -t "$meter"\
2020+
print -v cpu_out_var -m $((pt_line+y)) $pt_col -rs -fg $p_normal_color -jl 7 -t "$name" -fg ${theme[inactive_fg]} "⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀" -l 10 -t "$meter"\
20212021
-fg $cpu_p_color -jr 4 -t "${cpu_usage[i]}" -fg $p_normal_color -t "%"
20222022
if [[ $check_temp == true ]]; then
2023-
print -v cpu_out_var -fg 30 " ⡀⡀⡀⡀⡀" -l 7 -t " ${!temp_name}" -fg $temp_color -jr 4 -t ${cpu[temp_${i}]} -fg $p_normal_color -t ${cpu[temp_unit]}
2023+
print -v cpu_out_var -fg ${theme[inactive_fg]} " ⡀⡀⡀⡀⡀" -l 7 -t " ${!temp_name}" -fg $temp_color -jr 4 -t ${cpu[temp_${i}]} -fg $p_normal_color -t ${cpu[temp_unit]}
20242024
fi
20252025

20262026
if (( i>(p_height-2)*( p_width/(24+temp_width) )-( p_width/(24+temp_width) )-1 )); then break; fi
20272027
done
20282028

20292029
#* Print current CPU frequency right of the title in the meter box
2030-
print -v cpu_out_var -m $((p_line-1)) $((p_col+p_width-5-${#cpu[freq_string]})) -fg 30 -t "" -fg ${theme[title]} -b -t "${cpu[freq_string]}" -rs -fg 30 -t ""
2030+
print -v cpu_out_var -m $((p_line-1)) $((p_col+p_width-5-${#cpu[freq_string]})) -fg ${theme[div_line]} -t "" -fg ${theme[title]} -b -t "${cpu[freq_string]}" -rs -fg ${theme[div_line]} -t ""
20312031

20322032
#* Print created text, graph and meters to output variable
20332033
draw_out+="${cpu_graph_a[*]}${cpu_graph_b[*]}${cpu_out_var}"
@@ -2150,9 +2150,9 @@ draw_mem() { #? Draw mem, swap and disk statistics
21502150
draw_processes() { #? Draw processes and values to screen
21512151
local argument="$1"
21522152
if [[ -n $skip_process_draw && $argument != "now" ]]; then return; fi
2153-
local line=${box[processes_line]} col=${box[processes_col]} width=${box[processes_width]} height=${box[processes_height]} out_line y=1 fg_step_r fg_step_g fg_step_b checker=2 page_string
2153+
local line=${box[processes_line]} col=${box[processes_col]} width=${box[processes_width]} height=${box[processes_height]} out_line y=1 fg_step_r=0 fg_step_g=0 fg_step_b=0 checker=2 page_string
21542154
local reverse_string reverse_pos order_left="───────────┤" filter_string current_num detail_location det_no_add com_fg pg_arrow_up_fg pg_arrow_down_fg
2155-
local pid=0 pid_graph pid_step_r pid_step_g pid_step_b pid_add_r pid_add_g pid_add_b bg_add bg_step rgb_d=70 d_step proc_start up_fg down_fg page_up_fg page_down_fg this_box=processes
2155+
local pid=0 pid_graph pid_step_r pid_step_g pid_step_b pid_add_r pid_add_g pid_add_b bg_add bg_step proc_start up_fg down_fg page_up_fg page_down_fg this_box=processes
21562156
local d_width=${box[details_width]} d_height=${box[details_height]} d_line=${box[details_line]} d_col=${box[details_col]}
21572157
local detail_graph_width=$((d_width/3+2)) detail_graph_height=$((d_height-1)) kill_fg det_mod fg_add_r fg_add_g fg_add_b
21582158
local right_width=$((d_width-detail_graph_width-2))
@@ -2169,8 +2169,6 @@ draw_processes() { #? Draw processes and values to screen
21692169
pid_add_r=$(( (pid_r-(pid_r/6) )/height))
21702170
pid_add_g=$(( (pid_g-(pid_g/6) )/height))
21712171
pid_add_b=$(( (pid_b-(pid_b/6) )/height))
2172-
#p_add=$((110/height))
2173-
d_add=$((rgb_d/height))
21742172

21752173
unset proc_out
21762174

@@ -2185,7 +2183,6 @@ draw_processes() { #? Draw processes and values to screen
21852183

21862184
if [[ ${#detail_history[@]} -eq 1 ]] || ((resized>0)); then
21872185
unset proc_det2
2188-
#detail_mem_graph ${#detail_history[@]} -lt 2
21892186
create_graph -o detail_graph -d $((d_line+1)) $((d_col+1)) ${detail_graph_height} ${detail_graph_width} -c color_cpu_graph -n detail_history
21902187
if ((tty_width>120)); then create_mini_graph -o detail_mem_graph -w $((right_width/3-3)) -nc detail_mem_history; fi
21912188
det_no_add=1
@@ -2268,7 +2265,7 @@ draw_processes() { #? Draw processes and values to screen
22682265
if ((det_columns>=5)); then print -v proc_out -jc $((right_width/det_columns-1)) -t "${proc[detailed_threads]}"; fi
22692266

22702267
print -v proc_out -m $((d_line+4)) ${right_col} -fg ${theme[title]} -b -jr $((right_width/3+2)) -t "Memory: ${proc[detailed_mem]}%" -t " "
2271-
if ((tty_width>120)); then print -v proc_out -rs -fg 30 -rp $((right_width/3-3)) "" -l $((right_width/3-3)) -fg ${theme[proc_misc]} -t "${detail_mem_graph}" -t " "; fi
2268+
if ((tty_width>120)); then print -v proc_out -rs -fg ${theme[inactive_fg]} -rp $((right_width/3-3)) "" -l $((right_width/3-3)) -fg ${theme[proc_misc]} -t "${detail_mem_graph}" -t " "; fi
22722269
print -v proc_out -fg ${theme[title]} -b -t "${proc[detailed_mem_string]}"
22732270
fi
22742271

@@ -2286,8 +2283,6 @@ draw_processes() { #? Draw processes and values to screen
22862283
pid_r="$(( pid_r-( pid_add_r*(proc[selected]-1) ) ))"
22872284
pid_g="$(( pid_g-( pid_add_g*(proc[selected]-1) ) ))"
22882285
pid_b="$(( pid_b-( pid_add_b*(proc[selected]-1) ) ))"
2289-
2290-
rgb_d="$(( 70-( d_add*(proc[selected]-1) ) ))"
22912286
fi
22922287

22932288
current_num=1
@@ -2305,7 +2300,8 @@ draw_processes() { #? Draw processes and values to screen
23052300
print -v proc_out -m $((line+y)) $((col+1)) -t "${out_line::$((width-3))} "
23062301

23072302
if ((current_num==proc[selected])); then print -v proc_out -rs -bg ${theme[selected_bg]}; fi
2308-
print -v proc_out -m $((line+y)) $((col+width-12)) -fg $((rgb_d-d_step)) $((rgb_d-d_step)) $((rgb_d-d_step)) -t "⡀⡀⡀⡀⡀"
2303+
2304+
print -v proc_out -m $((line+y)) $((col+width-12)) -fg ${theme[inactive_fg]} -t "⡀⡀⡀⡀⡀"
23092305

23102306
if [[ -n ${!pid_graph} ]]; then
23112307
print -v proc_out -m $((line+y)) $((col+width-12)) -fg $((pid_r-pid_step_r)) $((pid_g-pid_step_g)) $((pid_b-pid_step_b)) -t "${!pid_graph}"
@@ -2317,11 +2313,9 @@ draw_processes() { #? Draw processes and values to screen
23172313
if ((current_num<proc[selected]+1)); then
23182314
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))
23192315
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))
2320-
d_step=$((d_step-d_add))
23212316
elif ((current_num>=proc[selected])); then
23222317
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))
23232318
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))
2324-
d_step=$((d_step+d_add))
23252319
fi
23262320

23272321
done
@@ -2344,7 +2338,6 @@ draw_processes() { #? Draw processes and values to screen
23442338
if ((tty_width>100)); then
23452339
reverse_string="-fg ${box[processes_color]} -t ┤ -fg ${theme[hi_fg]}${proc[reverse]:+ -ul} -b -t r -fg ${theme[title]} -t everse -rs -fg ${box[processes_color]} -t ├"
23462340
reverse_pos=9
2347-
#unset order_left
23482341
fi
23492342
print -v proc_misc -m $line $((col+width-${#proc_sorting}-8-reverse_pos)) -rs ${reverse_string}\
23502343
-fg ${box[processes_color]} -t "" -fg ${theme[hi_fg]} -b -t "" -fg ${theme[title]} -t " ${proc_sorting} " -fg ${theme[hi_fg]} -t "" -rs -fg ${box[processes_color]} -t ""
@@ -2498,7 +2491,7 @@ unpause_() { #? Unpause
24982491
}
24992492

25002493
menu_() { #? Shows the main menu overlay
2501-
local menu i count keypress selected_int=0 selected up local_rez d_banner=1 menu_out bannerd skipped menu_pause out_out wait_string
2494+
local menu i count keypress selected_int=0 selected up local_rez d_banner=1 menu_out bannerd skipped menu_pause out_out wait_string trans
25022495
local -a menus=("options" "help" "quit") color
25032496

25042497
until false; do
@@ -2525,6 +2518,7 @@ menu_() { #? Shows the main menu overlay
25252518
print -v menu_out -d 1 -rs
25262519
selected="${menus[selected_int]}"
25272520
unset up
2521+
if ((${theme[main_bg_dec]// /*}>255**3/2)); then print -v menu_out -bg "#00"; unset trans; else trans=" -trans"; fi
25282522
for menu in "${menus[@]}"; do
25292523
if [[ $menu == "$selected" ]]; then
25302524
local -n menu_array="menu_${menu}_selected"
@@ -2535,10 +2529,10 @@ menu_() { #? Shows the main menu overlay
25352529
fi
25362530
up=$((up+${#menu_array[@]}))
25372531
for((i=0;i<${#menu_array[@]};i++)); do
2538-
print -v menu_out -d 1 -fg ${color[i]} -c -trans -t "${menu_array[i]}"
2532+
print -v menu_out -d 1 -fg ${color[i]} -c${trans} -t "${menu_array[i]}"
25392533
done
25402534
done
2541-
print -v menu_out -u ${up}
2535+
print -v menu_out -rs -u ${up}
25422536
fi
25432537
unset out_out
25442538
out_out="${menu_pause}${menu_out}"
@@ -2760,21 +2754,19 @@ options_() { #? Shows the options overlay
27602754
fi
27612755

27622756
if [[ -n $redraw_misc ]]; then
2763-
unset options_misc
2757+
unset options_misc redraw_misc
27642758
col=$((tty_width/2-39))
27652759
line=$((tty_height/2-4))
27662760
desc_col=$((col+30))
27672761
draw_banner "$((tty_height/2-11))" options_misc
27682762
create_box -v options_misc -w 29 -h $((${#options_array[@]}*2+2)) -l $line -c $((col-1)) -fill -lc ${theme[div_line]} -title "options"
2769-
unset redraw_misc
27702763
fi
27712764

27722765

27732766
if [[ -n $keypress || -z $options_out ]]; then
2774-
unset options_out desc_height
2767+
unset options_out desc_height lr inp valid
27752768
selected="${options_array[selected_int]}"
27762769
local -n selected_desc="desc_${selected}"
2777-
unset lr inp valid
27782770
if [[ $background_update == false ]]; then desc_pos=$line; desc_height=$((${#options_array[@]}*2+2))
27792771
elif ((selected_int*2+${#selected_desc[@]}<${#options_array[@]}*2)); then desc_pos=$((line+selected_int*2))
27802772
else desc_pos=$((line+${#options_array[@]}*2-${#selected_desc[@]})); fi
@@ -2819,21 +2811,19 @@ options_() { #? Shows the options overlay
28192811
if [[ -n $theme_check ]]; then
28202812
local -a theme_index
28212813
local git_theme new_themes=0
2822-
unset 'theme_index[@]' options_out
2814+
unset 'theme_index[@]' 'desc_color_theme[-1]' options_out
28232815
theme_index=($(curl -m 3 --raw https://raw.githubusercontent.com/aristocratos/bashtop/master/themes/index.txt 2>/dev/null))
28242816
if [[ ${theme_index[*]} =~ .theme ]]; then
28252817
for git_theme in ${theme_index[@]}; do
2826-
if [[ ! -e "${theme_dir}/${git_theme}" ]]; then
2818+
if [[ $git_theme =~ .theme && ! -e "${theme_dir}/${git_theme}" ]]; then
28272819
if curl -m 3 --raw "https://raw.githubusercontent.com/aristocratos/bashtop/master/themes/${git_theme}" >"${theme_dir}/${git_theme}" 2>/dev/null; then
28282820
((++new_themes))
28292821
themes+=("${git_theme%.theme}")
28302822
fi
28312823
fi
28322824
done
2833-
unset 'desc_color_theme[-1]'
28342825
desc_color_theme+=("Found ${new_themes} new theme(s)!")
28352826
else
2836-
unset 'desc_color_theme[-1]'
28372827
desc_color_theme+=("ERROR: Couldn't get theme index!")
28382828
fi
28392829
fi
@@ -2984,7 +2974,7 @@ options_() { #? Shows the options overlay
29842974
}
29852975

29862976
killer_() { #? Kill process with selected signal
2987-
local kill_op="$1" kill_pid="$2" killer_out killer_box col line program keypress selected selected_int=0 sig confirmed=0 option killer_pause status status_fg msg
2977+
local kill_op="$1" kill_pid="$2" killer_out killer_box col line program keypress selected selected_int=0 sig confirmed=0 option killer_pause status msg
29882978
local -a options=("yes" "no")
29892979

29902980
if ! program="$(ps -o comm --no-header -p ${kill_pid})"; then return; fi
@@ -3024,8 +3014,8 @@ killer_() { #? Kill process with selected signal
30243014
elif ((confirmed==1)); then
30253015
selected="ok"
30263016
print -v killer_out -m $((line+2)) $col -fg ${theme[title]} -b -jc 38 -t "Sending signal ${sig} to pid ${kill_pid}!"
3027-
print -v killer_out -m $((line+4)) $col -fg ${status_fg} -jc 38 -t "${status^}!" -m $((line+6)) $col
3028-
if [[ -n $msg ]]; then print -v killer_out -m $((line+5)) $col -fg ee -jc 38 -t "${msg}" -m $((line+7)) $col; fi
3017+
print -v killer_out -m $((line+4)) $col -fg ${theme[main_fg]} -jc 38 -t "${status^}!" -m $((line+6)) $col
3018+
if [[ -n $msg ]]; then print -v killer_out -m $((line+5)) $col -fg ${theme[main_fg]} -jc 38 -t "${msg}" -m $((line+7)) $col; fi
30293019
print -v killer_out -fg ${theme[selected_fg]} -bg ${theme[selected_bg]} -b -r 15 -t "[ Ok ]" -rs
30303020
fi
30313021

@@ -3065,7 +3055,6 @@ killer_() { #? Kill process with selected signal
30653055
elif ((confirmed>0)) && [[ -z $status ]]; then
30663056
if kill -${sig} ${kill_pid} >/dev/null 2>&1; then
30673057
status="success"
3068-
status_fg="30ee20"
30693058
else
30703059
if ! ps -p ${kill_pid} >/dev/null 2>&1; then
30713060
msg="Process not running."
@@ -3074,7 +3063,7 @@ killer_() { #? Kill process with selected signal
30743063
else
30753064
msg="Unknown error."
30763065
fi
3077-
status="failed"; status_fg="ee3020"; fi
3066+
status="failed"; fi
30783067
fi
30793068

30803069

0 commit comments

Comments
 (0)