Re: ASCII formatting for plain text email
On Tue, Jan 31, 2023 at 05:32:07PM -0500, Greg Wooledge wrote:
> Again, a programming language can easily take an input string, measure
> its length in characters, and produce an output string that looks like
> a "box" around the input string. (Less easily if full Unicode is in play.)
Here's a simple bash function:
tbox() {
local len=$((${#1}+4)) row='########'
while ((${#row} < len)); do row+=$row; done
printf "%.${len}s\n# %s #\n%.${len}s\n" "$row" "$1" "$row"
}
Add that to your .bashrc and source it (or however you prefer to deal
with bash functions), and then:
unicorn:~$ tbox 'hello world'
###############
# hello world #
###############
Feel free to adapt it however you see fit.
Reply to: