diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/globals | 6 | ||||
-rw-r--r-- | src/hooks/arch | 42 | ||||
-rwxr-xr-x | src/hooks/fancy | 84 | ||||
-rw-r--r-- | src/network | 4 |
4 files changed, 87 insertions, 49 deletions
diff --git a/src/globals b/src/globals index eb9f934..f8d30ef 100644 --- a/src/globals +++ b/src/globals @@ -23,14 +23,10 @@ function report_err { echo "$*" } -function report_warn { +function report_notice { echo "$*" } -function report_notify { - true -} - function report_debug { checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2 } diff --git a/src/hooks/arch b/src/hooks/arch deleted file mode 100644 index c5d0587..0000000 --- a/src/hooks/arch +++ /dev/null @@ -1,42 +0,0 @@ -. /etc/rc.conf -. /etc/rc.d/functions - -### Logging/Error reporting for Arch Linux - -function report_err { - printhl "$*" -} - -function report_warn { - printhl "$*" -} - -function report_try { - stat_busy "$*" - REPORT_TRYING=1 -} - -function report_fail { - if [[ -n "$*" ]]; then - if [[ -n "$REPORT_TRYING" ]]; then - stat_append "- $*" - REPORT_TRYING= - stat_fail - else - printhl "$*" - fi - elif [[ -n "$REPORT_TRYING" ]]; then - REPORT_TRYING= - stat_fail - fi -} - -function report_success { - if [[ -n "$*" ]]; then - stat_append "- $*" - REPORT_TRYING= - fi - stat_done -} - -# vim: ft=sh ts=4 et sw=4: diff --git a/src/hooks/fancy b/src/hooks/fancy new file mode 100755 index 0000000..f0ad3bb --- /dev/null +++ b/src/hooks/fancy @@ -0,0 +1,84 @@ +# Fancy output is for terminal output only. +[[ -t 1 ]] || return + + +### Fancy Logging/Error reporting + +function report_err { + print_prefixed "${C_PREFIX}" "${C_HIGHLIGHT}$*" +} + +function report_notice { + print_prefixed "${C_PREFIX}" "$*" +} + +function report_try { + printf "${C_PREFIX}${PREFIX_BUSY}${C_NORMAL} %s " "$*" + report_status " BUSY " "${C_BUSY}" + REPORT_TRYING=1 +} + +function report_fail { + if [[ -n "$*" ]]; then + if [[ -n "$REPORT_TRYING" ]]; then + report_append "$*" + report_status "FAILED" "${C_FAILED}" $'\n' + REPORT_TRYING= + else + print_prefixed "${C_FAILED}" "${C_HIGHLIGHT}$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + report_status "FAILED" "${C_FAILED}" $'\n' + REPORT_TRYING= + fi +} + +function report_success { + if [[ -n "$*" ]]; then + if [[ -n "$REPORT_TRYING" ]]; then + report_append "$*" + report_status " DONE " "${C_DONE}" $'\n' + REPORT_TRYING= + else + print_prefixed "${C_DONE}" "$*" + fi + elif [[ -n "$REPORT_TRYING" ]]; then + report_status " DONE " "${C_DONE}" $'\n' + REPORT_TRYING= + fi +} + +function report_append { + printf -- "${RESTORE_POSITION}${C_PREFIX}-${C_NORMAL} %s " "$*" +} + +function report_status { + local status=$1 color=$2 + shift 2 + printf "${CURSOR_STATUS} [${color}%s${C_NORMAL}] %s" "$status" "$*" +} + +function print_prefixed { + local c_prefix=$1 + shift + printf "${c_prefix}${PREFIX_ATTENTION}${C_NORMAL} %s${C_NORMAL}\n" "$*" +} + + +SAVE_POSITION=$(tput sc) +RESTORE_POSITION=$(tput rc) +COLUMNS=$(tput cols) +(( COLUMNS == 0 )) && COLUMNS=80 +CURSOR_STATUS=${SAVE_POSITION}$(tput hpa $(( COLUMNS - 10 )) ) + +C_NORMAL=$(tput sgr0) +C_HIGHLIGHT=${C_NORMAL}$(tput bold) +C_PREFIX=${C_HIGHLIGHT}$(tput setaf 4) # blue +C_BUSY=${C_NORMAL}$(tput setaf 6) # cyan +C_FAILED=${C_HIGHLIGHT}$(tput setaf 1) # red +C_DONE=${C_HIGHLIGHT}$(tput setaf 2) # green + +PREFIX_BUSY="::" +PREFIX_ATTENTION=" >" + +# vim: ft=sh ts=4 et sw=4: diff --git a/src/network b/src/network index 30f9e89..9bdd720 100644 --- a/src/network +++ b/src/network @@ -64,7 +64,7 @@ interface_suspend() # the pipe to "while read" will create a subshell INTERFACE=$(. "$STATE_DIR/profiles/$prof"; echo "$INTERFACE") if [[ "$1" == all || "$1" == "$INTERFACE" ]]; then - report_notify "suspending interface $INTERFACE with profile $prof" + report_notice "suspending interface $INTERFACE with profile $prof" cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/" if checkyesno "${2:-yes}"; then profile_down "$prof" @@ -88,7 +88,7 @@ all_resume() # the pipe to "while read" will create a subshell INTERFACE=$(. "$STATE_DIR/suspend/$prof"; echo "$INTERFACE") if [[ $# -eq 0 || ! " $* " =~ " $INTERFACE " ]]; then - report_notify "resuming interface $INTERFACE with profile $prof" + report_notice "resuming interface $INTERFACE with profile $prof" profile_up "$prof" rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this fi |