feat(script): Add colored print (#1)

This commit is contained in:
hygienic-books 2023-03-06 02:03:54 +01:00
parent f5bb694768
commit f8592c215a

View File

@ -31,6 +31,32 @@ if [[ ! "${snap_op_installation_suffix}" ]]; then snap_op_installation_suffix='i
if [[ ! "${snap_op_remove_suffix}" ]]; then snap_op_remove_suffix='rmvl'; fi if [[ ! "${snap_op_remove_suffix}" ]]; then snap_op_remove_suffix='rmvl'; fi
if [[ ! "${snap_op_upgrade_suffix}" ]]; then snap_op_upgrade_suffix='upgr'; fi if [[ ! "${snap_op_upgrade_suffix}" ]]; then snap_op_upgrade_suffix='upgr'; fi
function pprint () {
local style msg exit_code
style="${1:?}"
msg="${2:?}"
exit_code="${3}"
local color_reset color_lyellow
color_reset='\e[0m'
color_lyellow='\e[93m'
color_red='\e[31m'
case "${style}" in
warn)
printf -- "${color_lyellow}"'[WARN]'"${color_reset}"' %s\n' "${msg}"
;;
err)
printf -- "${color_red}"'[ERR]'"${color_reset}"' %s\n' "${msg}"
;;
*)
printf -- '[INFO] %s\n' "${msg}"
;;
esac
[[ "${exit_code}" ]] && exit "${exit_code}"
}
function split_pkgs_by_importance () { function split_pkgs_by_importance () {
local pkgs_in_transaction local pkgs_in_transaction
pkgs_in_transaction=("${@}") pkgs_in_transaction=("${@}")