diff --git a/docs/lib/ui.md b/docs/lib/ui.md index cec4698..7b1115d 100644 --- a/docs/lib/ui.md +++ b/docs/lib/ui.md @@ -129,7 +129,7 @@ print-run-time ## print-section -Print section header: blue background and white letters followed by a line of `=` chars as wide as the header. +Print section header: blue background and white letters followed by a line of `~` chars as wide as the header. **Usage** @@ -154,3 +154,19 @@ print-status MESSAGE Params: MESSAGE Status message ``` + +--- + +## print-title + +Print title: blue background and white letters followed by a line of `~` chars. +Title is centered add padded with whitespace to 80 characters wide so the whole title line is highlighted in blue. + +**Usage** + +``` +print-title TITLE + +Params: +TITLE Title text +``` diff --git a/lib/ui.sh b/lib/ui.sh index f6d269e..824fd7b 100644 --- a/lib/ui.sh +++ b/lib/ui.sh @@ -31,25 +31,58 @@ print-error() { echo -e "${TXT_RED}${TXT_BOLD}${*}${TXT_NORM}" >&2 } +## Print title +## +## @param $* Title +###################### +print-title() { + local title="${*}" + local length padding_left padding_right min_width + [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 + + min_width=80 + length="${#title}" + padding_left=$(((min_width - length) / 2)) + padding_right=$((min_width - length - padding_left)) + [[ "${length}" -lt "${min_width}" ]] && length="${min_width}" + + echo + echo -ne "${BACK_BLUE}" + for ((i = 0 ; i < padding_left ; i++)); do + echo -n " " + done + echo -n "${title}" + for ((i = 0 ; i < padding_right ; i++)); do + echo -n " " + done + echo -e "${TXT_NORM}" + echo -ne "${BACK_BLUE}" + for ((i = 0 ; i < length ; i++)); do + echo -n "~" + done + echo -e "${TXT_NORM}" +} + ## Print section header ## -## @param $* Message -######################## +## @param $* Header +####################### print-section() { - local msg="${*}" + local header="${*}" [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 echo - echo -e "${BACK_BLUE}${msg}${TXT_NORM}" - for ((i = 0 ; i < ${#msg} ; i++)); do - echo -ne "${BACK_BLUE}=${TXT_NORM}" + echo -e "${BACK_BLUE}${header}${TXT_NORM}" + echo -ne "${BACK_BLUE}" + for ((i = 0 ; i < ${#header} ; i++)); do + echo -n "~" done - echo + echo -e "${TXT_NORM}" } ## Print header ## -## @param $* Message -######################## +## @param $* Header +####################### print-header() { [[ -n "${ES_PRINT_HUSH:-}" ]] && return 0 echo