General: Delete most of info() and instead call prin()

This commit is contained in:
Dylan Araps 2016-12-14 19:53:03 +11:00
parent 0933bfe1ae
commit bdcb0955c4

View file

@ -2425,9 +2425,6 @@ scrot_program() {
# TEXT FORMATTING # TEXT FORMATTING
info() { info() {
# $1 is the subtitle
subtitle="$1"
# Call the function. # Call the function.
"get_${2:-$1}" 2>/dev/null "get_${2:-$1}" 2>/dev/null
@ -2435,61 +2432,54 @@ info() {
output="${2:-$1}" output="${2:-$1}"
output="$(trim "${!output}")" output="$(trim "${!output}")"
# If prin was used in the function, stop here.
[[ "$prin" ]] && \
unset prin && return
# If the output is empty, don't print anything. # If the output is empty, don't print anything.
[[ -z "${output// }" ]] && \ [[ -z "${output// }" ]] && \
err "Info: Couldn't detect $subtitle." && return { err "Info: Couldn't detect ${1}."; return; }
case "$1" in case "$1" in
"title") "title")
string="${title_color}${bold}${output}" string="${title_color}${bold}${output}"
string="${string/@/${at_color}@${title_color}${bold}}" string="${string/@/${at_color}@${title_color}${bold}}"
length="${#output}" length="${#output}"
prin "$string"
;; ;;
"underline") string="${underline_color}${output}" ;; "underline")
string="${underline_color}${output}"
prin "$string"
;;
*) *)
string="${subtitle_color}${bold}${subtitle}${reset}" if [[ "$2" && "${output// }" ]]; then
string+="${colon_color}: ${info_color}${output}" length="$((${#1} + ${#output} + 2))"
length="$((${#subtitle} + ${#output} + 2))" prin "$1" "$output"
elif [[ "${output// }" ]]; then
length="${#output}"
prin "$output"
fi
;; ;;
esac esac
# If there's no subtitle don't print one
[[ -z "$2" ]] && string="${string/*: }"
# Print the string
printf "%b\n" "\033[${text_padding}C${zws}${string}${reset} "
# Calculate info height
info_height="$((info_height+=1))"
} }
prin() { prin() {
string="${1//$'\033[0m'}${2:+: $2}" subtitle="${1//$'\033[0m'}"
string="${2:+: $2}"
# If $2 doesn't exist we format $1 as info # If $2 doesn't exist we format $1 as info
[[ -z "$2" ]] && local subtitle_color="$info_color" [[ -z "$2" ]] && local subtitle_color="$info_color"
# Format the output # Format the output
string="$(trim "$string")"
string="${subtitle}${string}"
string="${string/:/${reset}${colon_color}:${info_color}}" string="${string/:/${reset}${colon_color}:${info_color}}"
string="${subtitle_color}${bold}${string}" string="${subtitle_color}${bold}${string}"
# Trim whitespace
string="$(trim "$string")"
# Print the info # Print the info
printf "%b\n" "\033[${text_padding}C${zws}${string}${reset} " printf "%b\n" "\033[${text_padding}C${zws}${string}${reset} "
# Calculate info height # Calculate info height
info_height="$((info_height+=1))" info_height="$((info_height+=1))"
# Tell info() that prin() was used.
prin=1
} }
get_underline() { get_underline() {