add _clearLine_

This commit is contained in:
Nathaniel Landau
2021-10-22 15:56:22 -04:00
parent 4c99e7fe6c
commit 49468383f2
3 changed files with 33 additions and 8 deletions

View File

@@ -60,7 +60,7 @@
"\t\t#\t\t\t\t\t\t\t 1: Failure",
"\t\t#\t\t\t\t\tstdout: ",
"\t\t# USAGE:",
"\t\t#\t\t\t\t\t${1:name} \"@\"",
"\t\t#\t\t\t\t\t_${1:name}_ \"@\"",
"\t\t",
"\t\t [[ $# == 0 ]] && fatal \"Missing required argument to ${FUNCNAME[0]}\"",
"\t\t",

View File

@@ -300,3 +300,22 @@ _columnizeOutput_() {
printf "%-${_leftIndent}s%-${_leftColumn}b %b\n" "" "${_key}" "${_line}"
done <<<"$(fold -w${_rightWrapLength} -s <<<"${_value}")"
}
_clearLine_() {
# DESC:
# Clears output in the terminal on the specified line number.
# ARGS:
# $1 (Optional): Line number to clear. (Defaults to 1)
# OUTS:
# 0: Success
# 1: Failure
# USAGE:
# _clearLine_ "2"
[ ! "$(declare -f "_isTerminal_")" ] && fatal "${FUNCNAME[0]} needs function _isTerminal_"
if _isTerminal_; then
local _line=${1:-1}
printf "\033[%sA\033[2K" "${_line}"
fi
}

View File

@@ -62,7 +62,9 @@ _useGNUutils_() {
# GNU utilities can be added to MacOS using Homebrew
[ ! "$(declare -f "_setPATH_")" ] && fatal "${FUNCNAME[0]} needs function _setPATH_"
[ ! "$(declare -f "_detectOS_")" ] && fatal "${FUNCNAME[0]} needs function _detectOS_"
if [[ $(_detectOS_) == mac ]]; then
if _setPATH_ \
"/usr/local/opt/gnu-tar/libexec/gnubin" \
"/usr/local/opt/coreutils/libexec/gnubin" \
@@ -72,4 +74,8 @@ _useGNUutils_() {
else
return 1
fi
else
# Always return 0 on non-MacOS
return 0
fi
}