forked from FNNDSC/pfcon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
boxes.sh
executable file
·54 lines (45 loc) · 1.07 KB
/
boxes.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# NAME
#
# boxes.sh
#
# DESC
#
# Draws left and right "box" outlines for a string of text
# in line by line fashion -- useful to create the "body" of
# a box of text, for example:
#
# │ Here is some text that │▒
# │ is created in a box of │▒
# │ some fixed width, with │▒
# │ a shadow effect also! │▒
#
. ./decorate.sh
let width=80
let b_clear=0
while getopts "c" opt; do
case $opt in
c) b_clear=1;;
esac
done
shift "$((OPTIND-1))"
# Set the default line color
if (( $# != 1 )) ; then
set -- ${White}
fi
# Grab the default or CLI passed color
lineColor=$1
if ((b_clear)) ; then
echo -en "\033[2A\033[2K"
fi
while IFS= read line; do
line="$(echo -e "${line}" | sed -e 's/[[:space:]]*$//')"
LINELEN=${#line}
TRAILLEN=$(( $width - $LINELEN ))
PADDING=""
if (( TRAILLEN > 0 )) ; then
PADDING=$(head -c $TRAILLEN < /dev/zero | tr '\0' ' ')
fi
printf "${Yellow}│${lineColor}${line}${PADDING}${Yellow}│${Brown}▒${NC}\n"
done