bashbot-lib/viewer.sh

26 lines
609 B
Bash
Raw Normal View History

2023-03-21 16:37:41 -03:00
#!/bin/bash
# this is just a library
# you will need to provide the following in the implementation:
# 1. a bash associative array populated by the library's functions
print_dashes(){
term_cols="$(tput cols)"
for ((i = 0; i < "${term_cols}"; i++)); do
printf -- "-"
done
}
view_content(){
local -n _REF="${1}"
print_dashes; printf "\n"
for i in "${!_REF[@]}"; do
[ "${i}" == "text" ] && {
printf "[%s] \t=\t" "${i}"
sed ':a;N;$!ba;s/\n/\\n/g' <<< "${_REF[${i}]}"
continue
}
2023-03-21 16:37:41 -03:00
[ ! -z "${_REF[${i}]}" ] && printf "[%s] \t=\t%s\n" "${i}" "${_REF[${i}]}"
done
}