Color prompts (#57)
* Implement function `ask` for prompts * Declare response variable for temperature unit as local * Rename user response variables (choice)
This commit is contained in:
parent
34c07fd2bc
commit
f5ff837770
@ -58,6 +58,12 @@ function err {
|
|||||||
echo -e "\e[0;31m[error] $1\e[0m"
|
echo -e "\e[0;31m[error] $1\e[0m"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ask {
|
||||||
|
read -p $'\n\e[0;32m'"$1:"$'\e[0m'" " response
|
||||||
|
echo $response
|
||||||
|
}
|
||||||
|
|
||||||
# End of helper functions
|
# End of helper functions
|
||||||
|
|
||||||
# Function to display usage information
|
# Function to display usage information
|
||||||
@ -71,8 +77,8 @@ function install_packages {
|
|||||||
# Check if the 'sensors' command is available on the system
|
# Check if the 'sensors' command is available on the system
|
||||||
if (! command -v sensors &>/dev/null); then
|
if (! command -v sensors &>/dev/null); then
|
||||||
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
# If the 'sensors' command is not available, prompt the user to install lm-sensors
|
||||||
read -p "lm-sensors is not installed. Would you like to install it? (y/n) " choice
|
local choiceInstallLmSensors=$(ask "lm-sensors is not installed. Would you like to install it? (y/n)")
|
||||||
case "$choice" in
|
case "$choiceInstallLmSensors" in
|
||||||
[yY])
|
[yY])
|
||||||
# If the user chooses to install lm-sensors, update the package list and install the package
|
# If the user chooses to install lm-sensors, update the package list and install the package
|
||||||
apt-get update
|
apt-get update
|
||||||
@ -92,7 +98,7 @@ function install_packages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configure {
|
function configure {
|
||||||
sensorsDetected=false
|
sensorsDetected=false # this is a global variable (see install_mod())
|
||||||
local sensorsOutput
|
local sensorsOutput
|
||||||
|
|
||||||
if [ $DEBUG_REMOTE = true ]; then
|
if [ $DEBUG_REMOTE = true ]; then
|
||||||
@ -121,19 +127,21 @@ function configure {
|
|||||||
if (echo "$sensorsOutput" | grep -q "coretemp-"); then
|
if (echo "$sensorsOutput" | grep -q "coretemp-"); then
|
||||||
# Intel CPU
|
# Intel CPU
|
||||||
# Prompt user for which temperature to use
|
# Prompt user for which temperature to use
|
||||||
read -p "Do you wish to display temperatures for all cores [C] or just an average value(s) per CPU [a]? (C/a): " choice
|
local choiceTempDisplayType=$(ask "Do you wish to display temperatures for all cores [C] or just an average temperature per CPU [a]? (C/a)")
|
||||||
case "$choice" in
|
case "$choiceTempDisplayType" in
|
||||||
# Set temperature search criteria
|
# Set temperature search criteria
|
||||||
[cC] | "")
|
[cC] | "")
|
||||||
if (echo "$sensorsOutput" | grep -A 10 "coretemp-" | grep -q "Core "); then
|
if (echo "$sensorsOutput" | grep -A 10 "coretemp-" | grep -q "Core "); then
|
||||||
CPU_ITEM_PREFIX="Core "
|
CPU_ITEM_PREFIX="Core "
|
||||||
CPU_TEMP_CAPTION="Core"
|
CPU_TEMP_CAPTION="Core"
|
||||||
|
info "Temperatures will be displayed for all cores."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
[aA])
|
[aA])
|
||||||
if (echo "$sensorsOutput" | grep -A 10 "coretemp-" | grep -q "Package id "); then
|
if (echo "$sensorsOutput" | grep -A 10 "coretemp-" | grep -q "Package id "); then
|
||||||
CPU_ITEM_PREFIX="Package id"
|
CPU_ITEM_PREFIX="Package id"
|
||||||
CPU_TEMP_CAPTION="Package"
|
CPU_TEMP_CAPTION="Package"
|
||||||
|
info "An average temperature will be displayed per CPU."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -231,10 +239,8 @@ function configure {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $sensorsDetected = true ]; then
|
if [ $sensorsDetected = true ]; then
|
||||||
echo
|
local choiceTempUnit=$(ask "Do you wish to display temperatures in degrees Celsius [C] or Fahrenheit [f]? (C/f)")
|
||||||
read -p "Do you wish to display temperature readings in degrees Celsius [C] or Fahrenheit [f]? (C/f): " TEMP_UNIT
|
case "$choiceTempUnit" in
|
||||||
|
|
||||||
case "$TEMP_UNIT" in
|
|
||||||
[cC] | "")
|
[cC] | "")
|
||||||
TEMP_UNIT="C"
|
TEMP_UNIT="C"
|
||||||
info "Temperatures will be presented in degrees Celsius."
|
info "Temperatures will be presented in degrees Celsius."
|
||||||
@ -250,9 +256,8 @@ function configure {
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
local choiceEnableSystemInfo=$(ask "Do you wish to enable system information? (Y/n)")
|
||||||
read -p "Do you wish to enable system information? (Y/n): " ENABLE_SYS_INFO
|
case "$choiceEnableSystemInfo" in
|
||||||
case "$ENABLE_SYS_INFO" in
|
|
||||||
[yY] | "")
|
[yY] | "")
|
||||||
enableSystemInfo=true
|
enableSystemInfo=true
|
||||||
info "System information will be displayed..."
|
info "System information will be displayed..."
|
||||||
@ -859,8 +864,8 @@ function save_sensors_data {
|
|||||||
msg "Sensors data will be saved in $filepath"
|
msg "Sensors data will be saved in $filepath"
|
||||||
|
|
||||||
# Prompt user for confirmation
|
# Prompt user for confirmation
|
||||||
read -p "Do you wish to continue? (y/n): " choice
|
local choiceContinue=$(ask "Do you wish to continue? (y/n)")
|
||||||
case "$choice" in
|
case "$choiceContinue" in
|
||||||
[yY])
|
[yY])
|
||||||
sensors -j >"$filepath"
|
sensors -j >"$filepath"
|
||||||
msgb "Sensors data saved in $filepath."
|
msgb "Sensors data saved in $filepath."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user