diff --git a/.version b/.version index 75a22a2..b0f2dcb 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.0.3 +3.0.4 diff --git a/doc/USAGE.md b/doc/USAGE.md index 86fb47a..b101bab 100644 --- a/doc/USAGE.md +++ b/doc/USAGE.md @@ -605,8 +605,18 @@ For each passed argument checks if it's installed. +* [output.screen-width.actual()](#outputscreen-widthactual) +* [output.screen-height.actual()](#outputscreen-heightactual) * [section()](#section) +### `output.screen-width.actual()` + +OS-independent way to determine screen width. + +### `output.screen-height.actual()` + +OS-independent way to determine screen height. + ### `section()` Prints a "arrow-like" line using powerline characters @@ -1839,20 +1849,6 @@ Prints values of all variables starting with prefixes in args ---- - - -## File `lib/background.sh` - -# lib/background.sh - - -Run a bunch of jobs on the background and wait for their completion - - - - - --- diff --git a/doc/USAGE.pdf b/doc/USAGE.pdf index be0c762..190d158 100644 Binary files a/doc/USAGE.pdf and b/doc/USAGE.pdf differ diff --git a/lib/output.sh b/lib/output.sh index 4955956..94fbb2e 100644 --- a/lib/output.sh +++ b/lib/output.sh @@ -24,6 +24,30 @@ function output.reset-min-max-width() { output.reset-min-max-width +# @description OS-independent way to determine screen width. +output.screen-width.actual() { + local w + util.os + if [[ ${AppCurrentOS} =~ darwin ]]; then + w="$(.output.stty.field columns)" + elif [[ ${AppCurrentOS} =~ linux ]]; then + w="$(stty -a 2>/dev/null | grep columns | awk '{print $7}' | sedx 's/;//g')" + fi + printf -- "%d" "$w" +} + +# @description OS-independent way to determine screen height. +output.screen-height.actual() { + local h + util.os + if [[ ${AppCurrentOS} =~ darwin ]]; then + h="$(.output.stty.field rows)" + elif [[ ${AppCurrentOS} =~ linux ]]; then + h="$(stty -a 2>/dev/null | grep rows | awk '{print $5}' | sedx 's/;//g')" + fi + printf -- "%d" "$h" +} + function output.constrain-screen-width() { export LibOutput__WidthDetectionStrategy="constrained" [[ $1 -gt 0 ]] && output.set-max-width "$1" @@ -105,7 +129,6 @@ cursor.restore() { printf "\e[u" } - output.print-at-x-y() { local x=$1 shift @@ -136,29 +159,26 @@ output.color.off() { .output.stty.field() { local field="$1" - stty -a 2>/dev/null| grep "${field}" | tr -d ';' | tr ' ' '\n' | grep -B 1 "${field}" | head -1 + stty -a 2>/dev/null | grep "${field}" | tr -d ';' | tr ' ' '\n' | grep -B 1 "${field}" | head -1 } - .output.current-screen-width.unconstrained() { - local w - util.os if output.is-pipe; then printf -- '%d' "${LibOutput__MaxWidth:-80}" else - if [[ ${AppCurrentOS} =~ darwin ]]; then - w="$(.output.stty.field columns)" - elif [[ ${AppCurrentOS} =~ linux ]]; then - w="$(stty -a 2>/dev/null | grep columns | awk '{print $7}' | sedx 's/;//g')" - fi - printf -- "%d" "$w" + output.screen-width.actual fi + } screen.width.actual() { .output.current-screen-width.unconstrained } +screen.height.actual() { + .output.screen-height +} + .output.current-screen-width.constrained() { local w=$(.output.current-screen-width.unconstrained) @@ -207,14 +227,7 @@ screen.width.actual() { } .output.screen-height() { - util.os - local h - if [[ ${AppCurrentOS} =~ darwin ]]; then - h="$(.output.stty.field rows)" - elif [[ ${AppCurrentOS} =~ linux ]]; then - h="$(stty -a 2>/dev/null | grep rows | awk '{print $5}' | sedx 's/;//g')" - fi - + local h=$(output.screen-height.actual) [[ -z ${h} ]] && h=${LibOutput__MinHeight} [[ ${h} -lt ${LibOutput__MinHeight} ]] && h=${LibOutput__MinHeight} printf -- $((h - 2)) @@ -397,7 +410,7 @@ ascii-clean() { .output.width() { local w=$(screen.width) - printf "%d" $((w - 4)) + printf "%d" $((w - 4)) } .output.left-as-is() { @@ -405,13 +418,15 @@ ascii-clean() { } .output.left-as-is.black-text() { - local bg="${1}"; shift # bar background - local tfg="${1}"; shift # text foreground + local bg="${1}" + shift # bar background + local tfg="${1}" + shift # text foreground local text="$*" local len=${#text} - len=$(( len + 5 )) - local tlen=$(( len - 5 )) + len=$((len + 5)) + local tlen=$((len - 5)) text="$(printf -- "%${tlen}.${tlen}s" "${text}")" local fg="${txtblk}" @@ -440,7 +455,7 @@ ascii-clean() { local text="$*" printf "\n${color}" if output.is-terminal; then - local width=$(( $(.output.width) - 4 )) + local width=$(($(.output.width) - 4)) printf -- " %-${width}.${width}s${clr}\n\n" "${text}" else printf -- " ❯❯ %-${width}.${width}s${clr}\n\n" "${text}" @@ -650,4 +665,3 @@ ui.closer.kind-of-ok:() { ui.closer.kind-of-ok $@ echo } - diff --git a/test/output_test.bats b/test/output_test.bats index 110e38c..4b805f2 100644 --- a/test/output_test.bats +++ b/test/output_test.bats @@ -8,7 +8,7 @@ source lib/output.sh source lib/color.sh source lib/util.sh -set +e +set -e @test "ascii-pipe() should remove color and other escape sequences from STDIN" { set -e @@ -31,3 +31,15 @@ set +e [[ ${is_pipe} -eq 1 ]] } +@test "output.screen-width.actual()" { + export COLUMNS=120 + local w=$(output.screen-width.actual) + [[ $w -eq 0 ]] +} + +@test "output.screen.height.actual()" { + export ROWS=20 + local h=$(output.screen-width.actual) + [[ $h -eq 0 ]] +} +