mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-14 07:53:46 -05:00
add tests for _columns_
This commit is contained in:
@@ -250,3 +250,13 @@ teardown() {
|
|||||||
|
|
||||||
assert_file_not_exist "${LOGFILE}"
|
assert_file_not_exist "${LOGFILE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "_columns_: key/value" {
|
||||||
|
run _columns_ "key" "value"
|
||||||
|
assert_output --regexp "^key.*value"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "_columns_: indented key/value" {
|
||||||
|
run _columns_ "key" "value" 1
|
||||||
|
assert_output --regexp "^ key.*value"
|
||||||
|
}
|
||||||
|
|||||||
@@ -287,12 +287,13 @@ _clearLine_() (
|
|||||||
|
|
||||||
_columns_() {
|
_columns_() {
|
||||||
# DESC:
|
# DESC:
|
||||||
# Prints a two column output from a key/value pair.
|
# Prints a two column output with fixed widths and wrapping text from a key/value pair.
|
||||||
# Optionally pass a number of 2 space tabs to indent the output.
|
# Optionally pass a number of 2 space tabs to indent the output.
|
||||||
# ARGS:
|
# ARGS:
|
||||||
# $1 (required): Key name (Left column text)
|
# $1 (required): Key name (Left column text)
|
||||||
# $2 (required): Long value (Right column text. Wraps around if too long)
|
# $2 (required): Long value (Right column text. Wraps around if too long)
|
||||||
# $3 (optional): Number of 2 character tabs to indent the command (default 1)
|
# $3 (optional): Number of 2 character tabs to indent the command (default 1)
|
||||||
|
# $4 (optional): Total character width of the left column (default 35)
|
||||||
# OPTS:
|
# OPTS:
|
||||||
# -b Bold the left column
|
# -b Bold the left column
|
||||||
# -u Underline the left column
|
# -u Underline the left column
|
||||||
@@ -321,18 +322,16 @@ _columns_() {
|
|||||||
|
|
||||||
local _key="${1}"
|
local _key="${1}"
|
||||||
local _value="${2}"
|
local _value="${2}"
|
||||||
local _tabLevel="${3-}"
|
local _tabLevel="${3:-0}"
|
||||||
|
local _leftColumnWidth="${4:-35}"
|
||||||
local _tabSize=2
|
local _tabSize=2
|
||||||
local _line
|
local _line
|
||||||
local _rightIndent
|
local _rightIndent
|
||||||
local _leftIndent
|
local _leftIndent
|
||||||
if [[ -z ${3-} ]]; then
|
|
||||||
_tabLevel=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
_leftIndent="$((_tabLevel * _tabSize))"
|
_leftIndent="$((_tabLevel * _tabSize))"
|
||||||
|
|
||||||
local _leftColumnWidth="$((30 + _leftIndent))"
|
local _leftColumnWidth="$((_leftColumnWidth - _leftIndent))"
|
||||||
|
|
||||||
if [ "$(tput cols)" -gt 180 ]; then
|
if [ "$(tput cols)" -gt 180 ]; then
|
||||||
_rightIndent=110
|
_rightIndent=110
|
||||||
|
|||||||
Reference in New Issue
Block a user