limit maximum output width to width of the terminal

This commit is contained in:
Tim Cooper 2018-12-25 16:13:32 -06:00
parent eb41fefb9c
commit fda81a610e
2 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,13 @@ BEGIN {
# $6 Verse
FS = "\t"
MAX_WIDTH = 80
if (ENVIRON["KJV_MAX_WIDTH"] ~ /^[0-9]+$/) {
if (int(ENVIRON["KJV_MAX_WIDTH"]) < MAX_WIDTH) {
MAX_WIDTH = int(ENVIRON["KJV_MAX_WIDTH"])
}
}
if (cmd == "ref") {
mode = parseref(ref, p)
p["book"] = cleanbook(p["book"])
@ -151,7 +158,7 @@ function printverse(verse, word_count, characters_printed) {
word_count = split(verse, words, " ")
for (i = 1; i <= word_count; i++) {
if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > 72) {
if (characters_printed + length(words[i]) + (characters_printed > 0 ? 1 : 0) > MAX_WIDTH - 8) {
printf("\n\t")
characters_printed = 0
}

5
kjv.sh
View File

@ -71,6 +71,11 @@ while [ $# -gt 0 ]; do
fi
done
cols=$(tput cols 2>/dev/null)
if [ $? -eq 0 ]; then
export KJV_MAX_WIDTH="$cols"
fi
if [ $# -eq 0 ]; then
if [ ! -t 0 ]; then
show_help