kjv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fda81a610e4be0e7c5cf242de655868762dda1d4
parent eb41fefb9c7c95544f17bd6c0346a4db57afe897
Author: Tim Cooper <tim.cooper@layeh.com>
Date:   Tue, 25 Dec 2018 16:13:32 -0600

limit maximum output width to width of the terminal

Diffstat:
Mkjv.awk | 9++++++++-
Mkjv.sh | 5+++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/kjv.awk b/kjv.awk @@ -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 } diff --git a/kjv.sh b/kjv.sh @@ -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