Skip to content

Instantly share code, notes, and snippets.

@flickerfly
Last active March 1, 2021 19:31
Show Gist options
  • Save flickerfly/2be36b87bd1beae8952e71e4a37a30a4 to your computer and use it in GitHub Desktop.
Save flickerfly/2be36b87bd1beae8952e71e4a37a30a4 to your computer and use it in GitHub Desktop.
# Print a 75 column box as long as needed with the input of one or more strings as paragraphs
# TODO: Figure out how to get printf to create 75 $hborder characters in a single line.
# TODO: Make the box width variable
function box_print() {
# The character that makes the box border
vborder="#"
hborder="#"
# Break input into a size that'll fit in the box
local string=$(echo "$@" | fmt -71 )
# bar is a line of #
header="%74s\n"
bar=$(printf "$header" "$hborder"|tr "[:space:]" "$hborder")
# blank is blank line inside the comment box
printf -v blank '%s%74s' "$vborder" "$vborder"
# Print Header
echo "$bar"
echo "$blank"
# Print Comment in borders
echo "$string" | while IFS='' read line; do
printf '%s %-71s %s\n' "$vborder" "$line" "$vborder"
done
# Print Footer
echo "$blank"
echo "$bar"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment