dotfiles/home/private_bin/executable_boxify

67 lines
1.6 KiB
Text
Raw Normal View History

2023-02-01 14:14:05 -06:00
#!/usr/bin/env bash
border_color=5
text_color=4
# why not python?
function boxify() {
local s=("$@") b w
for l in "${s[@]}"; do
((w < ${#l})) && {
b="$l"
w="${#l}"
}
done
tput setaf $border_color
echo "╭─${b//?/─}─╮
│ ${b//?/ } │"
for l in "${s[@]}"; do
printf '│ %s%*s%s │\n' "$(tput setaf $text_color)" "-$w" "$l" "$(tput setaf $border_color)"
done
echo "│ ${b//?/ } │
╰─${b//?/─}─╯"
tput sgr 0
}
# parse args
if [[ "$#" -eq 0 ]]; then
set -- "use boxify <text>"
fi
boxify "$@"
# 0 1 2 3 4 5 6 7 8 9 A B C D E F
# A ╷ ╶ ┌ ╴ ┐ ─ ┬ ╵ │ └ ├ ┘ ┤ ┴ ┼
# B ╭ ╮ ╰ ╯
#
# 0 1 2 3 4 5 6 7 8 9 A B C D E F
# U+250x ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏
# U+251x ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟
# U+252x ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯
# U+253x ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿
# U+254x ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏
# U+255x ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟
# U+256x ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯
# U+257x ╰ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿
# function boxify() {
# local s=("$@") b w
# for l in "${s[@]}"; do
# ((w < ${#l})) && {
# b="$l"
# w="${#l}"
# }
# done
# tput setaf 3
# echo " -${b//?/-}-
# | ${b//?/ } |"
# for l in "${s[@]}"; do
# printf '| %s%*s%s |\n' "$(tput setaf 4)" "-$w" "$l" "$(tput setaf 3)"
# done
# echo "| ${b//?/ } |
# -${b//?/-}-"
# tput sgr 0
# }
#
#