changes to keypress recognition

pull/19/head
aristocratos 2020-04-09 23:38:57 +02:00
parent 1fd6d0a0f8
commit c6dc57e408
1 changed files with 27 additions and 19 deletions

46
bashtop
View File

@ -40,7 +40,7 @@ banner=(
"██╔══██╗██╔══██║╚════██║██╔══██║ ██║ ██║ ██║██╔═══╝ " "██╔══██╗██╔══██║╚════██║██╔══██║ ██║ ██║ ██║██╔═══╝ "
"██████╔╝██║ ██║███████║██║ ██║ ██║ ╚██████╔╝██║ " "██████╔╝██║ ██║███████║██║ ██║ ██║ ╚██████╔╝██║ "
"╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ") "╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ")
declare version="0.6.11" declare version="0.6.12"
declare banner_width=${#banner[0]} declare banner_width=${#banner[0]}
banner_colors=("#E62525" "#CD2121" "#B31D1D" "#9A1919" "#801414") banner_colors=("#E62525" "#CD2121" "#B31D1D" "#9A1919" "#801414")
@ -1506,8 +1506,7 @@ collect_processes() { #? Collect process information and calculate accurate cpu
else breaking=1; fi else breaking=1; fi
fi fi
get_key -save if get_key -save && [[ ${#saved_key[@]} -gt 0 ]]; then return; fi
if ((${#saved_key[@]}>0)); then return; fi
work_array=(${readline}) work_array=(${readline})
@ -3047,14 +3046,20 @@ get_key() { #? Get one key from standard input and translate key code to readabl
if [[ -z $save && -n ${saved_key[0]} ]]; then key="${saved_key[0]}"; unset 'saved_key[0]'; saved_key=("${saved_key[@]}") if [[ -z $save && -n ${saved_key[0]} ]]; then key="${saved_key[0]}"; unset 'saved_key[0]'; saved_key=("${saved_key[@]}")
else else
if ! IFS= read -rsd '' -t ${wait_time:-0.0001} -n 1 key >/dev/null 2>&1; then key_out=""; return; fi unset key
IFS= read -rsd '' -t ${wait_time:-0.001} -n 1 key >/dev/null 2>&1 ||true
if [[ -z ${key+s} ]]; then
key_out=""
if [[ -z $save ]]; then return 0
else return 1; fi
fi
#* Read 3 more characters if a leading escape character is detected #* Read 3 more characters if a leading escape character is detected
if [[ $key == "${enter_key}" ]]; then key="enter" if [[ $key == "${enter_key}" ]]; then key="enter"
elif [[ $key == "${backspace}" ]]; then key="backspace" elif [[ $key == "${backspace}" ]]; then key="backspace"
elif [[ $key == "${tab}" ]]; then key="tab" elif [[ $key == "${tab}" ]]; then key="tab"
elif [[ $key == "$esc_character" ]]; then esc=1; read -rsn3 -t 0.001 key || true; fi elif [[ $key == "$esc_character" ]]; then esc=1; read -rsn3 -t 0.0001 key || true; fi
if [[ -z $key && $esc -eq 1 ]]; then key="escape" if [[ -z $key && $esc -eq 1 ]]; then key="escape"
elif [[ $esc -eq 1 ]]; then elif [[ $esc -eq 1 ]]; then
case "${key}" in case "${key}" in
@ -3085,11 +3090,10 @@ get_key() { #? Get one key from standard input and translate key code to readabl
esac esac
fi fi
read -srd '' -t 0.00001 -n 10000 || true
if [[ -n $save ]]; then saved_key+=("${key}"); return; fi
fi fi
if [[ -n $save && -n $key ]]; then saved_key+=("${key}"); return 0; fi
if [[ -n $ext_out ]]; then key_out="${key}" if [[ -n $ext_out ]]; then key_out="${key}"
else echo -n "${key}"; fi else echo -n "${key}"; fi
} }
@ -3258,21 +3262,21 @@ process_input() { #? Process keypresses for main ui
} }
collect_and_draw() { #? Run all collect and draw functions collect_and_draw() { #? Run all collect and draw functions
local task_int=1 local task_int=0
for task in processes cpu mem net; do for task in processes cpu mem net; do
((++task_int)) ((++task_int))
if [[ -n $pause_screen ]]; then if [[ -n $pause_screen && -n ${saved_key[0]} ]]; then
get_key -save return
if [[ -n ${saved_key[0]} ]]; then return; fi
else else
while ((${#saved_key[@]}>0)); do while [[ -n ${saved_key[0]} ]]; do
process_input process_input 0.001
unset late_update
done done
fi fi
collect_${task} collect_${task}
get_key -save if get_key -save; then process_input; fi
draw_${task} draw_${task}
get_key -save if get_key -save; then process_input; fi
draw_clock "$1" draw_clock "$1"
if ((resized>0 & resized<task_int)); then return; fi if ((resized>0 & resized<task_int)); then return; fi
done done
@ -3335,7 +3339,11 @@ main_loop() { #? main loop...
time_left=0 time_left=0
fi fi
#* Wait while reading input #* Wait while reading input
while [[ -n ${saved_key[0]} ]]; do
process_input
unset late_update
done
process_input "${wait_string}" process_input "${wait_string}"
#* Draw clock if set #* Draw clock if set