autospec/lib/libmsgmng.lib.in
Davide Madrisan 40a6110422 libraries, autospec: refactoring library loading to fix some issues
Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
2012-12-01 22:50:46 +01:00

81 lines
2.3 KiB
Bash

#!/bin/bash
# libmsgmng.lib -- @package@ library to manage debug/warning/error messages
# Copyright (C) 2005,2006,2008,2012 Davide Madrisan <davide.madrisan@gmail.com>
[ "$libmsgmng_is_loaded" = 1 ] || {
libmsgmng_is_loaded=1
[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] &&
echo $"this script requires bash version 2 or better" >&2 && exit 1
[ -r @libdir@/libtranslate.lib ] ||
{ echo "\
libmsgmng.lib: "$"library not found"": @libdir@/libtranslate.lib" 1>&2
exit 1; }
. @libdir@/libtranslate.lib
# notify family of message handling functions:
# - notify.debug
# - notify.warning
# - notify.error
# - notify.note
# args:
# $1 : message to print
# note:
# 1. debug messages are only printed if 'verbose' is great then '0'
# 2. error notifications are followed by a call to 'EXIT_FUNC'
# or 'exit' if this variable is unset
# (can set to 'return' for instance)
notify_def_msg="<"$"no message"">"
function notify.debug() {
[ ${verbose:-0} -gt 1 ] || return
echo -e "${WARN}DEBUG${NORM}: ${1:-$notify_def_msg}" 1>&2
}
notify.debug $"loading"": \`libmsgmng.lib'..."
function notify.warning() {
echo -e "${WARN}WARNING${NORM}: ${1:-$notify_def_msg}" 1>&2
}
function notify.error() {
echo -e "${EXIT}ERROR${NORM}: ${EXIT}${1:-$notify_def_msg}${NORM}" 1>&2
${EXIT_FUNC:-"exit"} 1
}
function notify.note() {
[ ${verbose:-0} -ge 0 ] || return
echo -e "${1:-$notify_def_msg}"
}
# function notify.enable_colors
# enable if possible the colorized output
# args:
# none
function notify.enable_colors() {
local color_scheme="${1:-default}"
if [ -r ~/.@package@.d/color-theme.${color_scheme} ]; then
. ~/.@package@.d/color-theme.${color_scheme}
notify.debug "loading ~/.@package@.d/color-theme.${color_scheme}"
elif [ -r /etc/@package@.d/color-theme.${color_scheme} ]; then
. /etc/@package@.d/color-theme.${color_scheme}
notify.debug "loading /etc/@package@.d/color-theme.${color_scheme}"
else
notify.warning \
$"unknown color theme \`$color_scheme': colors will be disabled"
ESC= CRIT= NOTE= WARN= EXIT= NORM=
fi
}
# function notify.disable_colors
# disable the colorized output
# args:
# none
function notify.disable_colors() {
ESC= CRIT= NOTE= WARN= EXIT= NORM=
}
} # endif $libmsgmng_is_loaded