dotfiles/home/private_bin/executable_boxify

66 lines
1.6 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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
# }
#
#