Box It!
boxit
is a small script written in awk and shell
that puts text centered in a little ascii box.
This is placed under the unlicense.
<<boxit>>=
#!/bin/sh
NROWS=58 # NROWS - 2
boxit() {
read -r -d '' SCRIPT <<EOF
BEGIN {
NROWS=58
printf "+"
for (i = 0; i < NROWS; i++) {
printf "-"
}
printf "+\n"
}
{
lsize = length(\$0)
lspace = (NROWS - lsize) / 2
rspace = lspace
if (lsize % 2 != 0) rspace--;
printf "|"
for (i = 0; i < lspace; i++) {
printf " "
}
printf \$0
for (i = 0; i < rspace; i++) {
printf " "
}
printf "|\n"
}
END {
printf "+"
for (i = 0; i < NROWS; i++) {
printf "-"
}
printf "+\n"
}
EOF
awk "$SCRIPT"
}
fold -s -w $NROWS | boxit
Use it like so:
$ printf "do\nall\nthings\nwith\nartlessness" | ./boxit
+----------------------------------------------------------+
| do |
| all |
| things |
| with |
| artlessness |
+----------------------------------------------------------+