Commit 5c7e323c authored by Paul Cammish's avatar Paul Cammish
Browse files

fix spacer length in output

parent a66c367c
......@@ -93,10 +93,9 @@ _centre() {
spacer="$1"
line="$2"
stripped_line="$( echo $line | sed 's|\\033[[0-9;]*m||g' )"
# as cut can't ignore the control codes, we need to work out of we need to add anything to the output to make it line up
if (( ${#stripped_line} % 2 )); then extra_char=$spacer ; else extra_char="" ; fi
if [ $VERBOSITY -gt 1 ]; then
# as cut can't ignore the control codes, we need to work out of we need to add anything to the output to make it line up
# in other cases we can just use cut to trim it down
if (( ${#stripped_line} % 2 )); then extra_char=$spacer ; else extra_char="" ; fi
col="$( tput cols )" || col=80
col=$((col - 3))
len=$(( ( col / 2 ) - ( ( ${#stripped_line} + 1 ) / 2 ) ))
......@@ -104,7 +103,7 @@ _centre() {
fi
col=78
len=$(( ( col / 2 ) - ( ( ${#stripped_line} + 1 ) / 2 ) ))
_log "$(for each in $(seq 1 $len); do printf "$spacer"; done) $stripped_line $(for each in $(seq 1 $len); do printf "$spacer"; done)$spacer" | cut -c 1-$((col))
_log "$(for each in $(seq 1 $len); do printf "$spacer"; done) $stripped_line $(for each in $(seq 1 $len); do printf "$spacer"; done)$extra_char" # | cut -c 1-$((col))
}
_centre_logonly() {
......@@ -112,9 +111,10 @@ _centre_logonly() {
spacer="$1"
line="$2"
stripped_line="$( echo $line | sed 's|\\033[[0-9;]*m||g' )"
if (( ${#stripped_line} % 2 )); then extra_char=$spacer ; else extra_char="" ; fi
col=78
len=$(( ( col / 2 ) - ( ( ${#stripped_line} + 1 ) / 2 ) ))
_log "$(for each in $(seq 1 $len); do printf "$spacer"; done) $stripped_line $(for each in $(seq 1 $len); do printf "$spacer"; done)$spacer" | cut -c 1-$((col))
_log "$(for each in $(seq 1 $len); do printf "$spacer"; done) $stripped_line $(for each in $(seq 1 $len); do printf "$spacer"; done)$extra_char" # | cut -c 1-$((col))
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment