From Gracious Bongo, 1 Week ago, written in Plain Text.
  1.  
  2. boxframe(){
  3.   # desc: draw a border at ($geo)-1 and print a message
  4.   # usage: boxframe "$n-cols" "$n-lines" "$style" "${msg[@]}"
  5.   [[ "$1" == "--help" ]] && printf -- "boxframe\noptions: 0:space 1:star 2:box 3:checker\n" && return 0
  6.  
  7.   declare opt col lin msg tl tr bl br h v
  8.   declare -a s
  9.  
  10.   # Assign box drawing chars where:
  11.   #l:┌    k:┐    m:└    j:┘   q:─    v:│
  12.   tl='l' tr='k' bl='m' br='j' h='q' v='x'
  13.   opt="$1"; col="$2"; lin="$3"
  14.   shift 3
  15.   msg="$(columnate 2 "$col" "$@")"
  16.  
  17.   #! "${DEBUG:+true}" 2<&- || printf -- "c: %s\nl: %s\nsty: %s\nav: %s\n" "$col" "$lin" "$style" "$@" >~/xtr.tst
  18.   horz(){ eval printf $'\x1b\(0%-1.1c' "$h{1..${col}"\}; }
  19.   vert(){ eval printf $'\x1b\(0\x1b[D%1.1s\x1b[B' "$v{1..${lin}"\}; }
  20.   #unionvert(){ local sol eol void=$'\x00'
  21.   #  [[ "${FUNCNAME[-1]}" == "lvert" ]] && sol=$'\x1b[-1K' eol="$void" || sol="\x1b[D" eol=$'\x1b[K\x1b[B'
  22.   #  eval printf $'\x1b\(0%1.1s%s%1.1s' "$sol" "$v{1..${lin}"\} "$eol"; } #    ^cursor back        ^cursor down
  23.   unionvert(){ local sol eol void=$'\x00'
  24.     [[ "${FUNCNAME[-1]}" == "lvert" ]] && sol=$'\x1b[-1K' eol="$void" || sol="$void" eol=$'\x1b[K'
  25.     eval printf $'\x1b\(0\x1b[D%1.1s%s%1.1s\x1B' "$sol" "$v{1..${lin}"\} "$eol"; }
  26.     # feilds:     ^chrset^cub  ^sol ^v^eol ^cud
  27.   lvert(){ unionvert; }
  28.   rvert(){ unionvert; }
  29.  
  30.   # Set style. example "j${tl}" "${tr}m" in:
  31.   #printf "\x1b[0;0H%s\r%s\x1b[${COLUMNS}C\b%s" "$(horz)" "j${tl}" "${tr}m" # top
  32.   case "$opt" in
  33.     0) s=(' ' ' ' ' ' ' ') ;;
  34.     1) s=('*' '*' '*' '*') ;;
  35.     2) s=('j' 'm' 'l' 'k') ;;
  36.     3) s=('a' 'a' 'a' 'a') ;;
  37.     # Use val?
  38.     #*) s=("$style" "$style" "$style" "$style") ;;
  39.     # Or as param?
  40.     #opt=*) s=("${opt#*=}" "${opt#*=}" "${opt#*=}" "${opt#*=}") ;;
  41.     # TODO: fill edges with ▒ instead of space
  42.     #fuzz) eval printf $'\x1b\(0\x1b[D%1.1s\x1b[B' "$v{1..${lin}"\}  ;;
  43.     *) s=(' ' ' ' ' ' ' ') ;;
  44.   esac
  45.  
  46.   # Do it the other way! print message, then walk the edge of the screen to draw box.
  47.   printf -- "\x1b[?25l\x1b[2;3H$msg" # Set cursor to invis in addition to printing
  48.   # Ordered as: top, right, left, bottom
  49.   printf "\x1b[0;0H%s\r%s\x1b[${col}C\b%s" "$(horz)" "${s[0]}${tl}" "${tr}${s[1]}"
  50.   printf "\x1b[2;${col}H%s%s\r%s"          "$(vert)" "$tr"          "$br"
  51.   printf "\x1b[2;3H%s%s\r%s"               "$(vert)" "$bl"          "$tl"
  52.   printf "\x1b[${lin};0H%s\b%s\r%s"        "$(horz)" "${br}${s[2]}" "${s[3]}${bl}"
  53. }
  54.  
captcha