Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/lib/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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
```
51 changes: 42 additions & 9 deletions lib/ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down