commit: 2a04715c2eaeeab1ed61ccaab24db839785ba038
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jan 30 02:45:54 2026 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 6 01:45:14 2026 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=2a04715c
Drop the bash routine from _update_columns()
Presently, the _update_columns() function may choose to run the true(1)
executable, so as to coerce bash into refreshing its COLUMNS variable in
response to SIGWINCH. However, consider the following facts:
- The number of columns need only be refreshed for the purposes of the
eend() and hr() functions.
- As of the preceding commit, stty(1) can be executed at intervals of no
less than 1 second apart (on most platforms).
- The true(1) hack cannot be employed from a subshell.
- While true(1) is a little faster than stty(1), the cumulative
difference tends to be insignificant beyond synthetic testing.
As such, there is no compelling reason to continue to employ the method
that is specific to bash. This commit drops said method, rendering the
function easier to read and maintain.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
functions/tty.sh | 51 +++++++++++++++------------------------------------
1 file changed, 15 insertions(+), 36 deletions(-)
diff --git a/functions/tty.sh b/functions/tty.sh
index 293f21c..6c47003 100644
--- a/functions/tty.sh
+++ b/functions/tty.sh
@@ -8,7 +8,6 @@
# The following variables affect initialisation and/or function behaviour.
# BASH : whether bash-specific features may be employed
-# BASHPID : may be used by _update_columns() and _update_pid()
# COLUMNS : may be used by _update_columns() to get the column count
# EPOCHREALTIME : potentially used by _update_time() to get the time
# TERM : used to detect dumb terminals
@@ -54,42 +53,22 @@ _should_throttle()
#
_update_columns()
{
- # shellcheck disable=3044
- if [ "${BASH}" ] && shopt -q checkwinsize; then
- genfun_bin_true=$(whenceforth -x true)
+ local IFS
+
+ if from_portage; then
+ # Python's pty module is broken. For now, expect for portage to
+ # have exported COLUMNS to the environment.
+ set -- 0 "${COLUMNS}"
+ elif _should_throttle 100 && [ "${genfun_cols}" ]; then
+ # Preserve the cached number of columns for up to 1 second.
+ return
+ else
+ # This use of stty(1) is portable as of POSIX-1.2024.
+ IFS=' '
+ # shellcheck disable=2046
+ set -- $(stty size 2>/dev/null)
fi
-
- _update_columns()
- {
- local IFS
-
- # Two optimisations are applied. Firstly, the rate at which
- # updates can be performed is throttled to intervals of one
- # second. Secondly, if running on bash then the COLUMNS variable
- # may be gauged, albeit only in situations where doing so can be
- # expected to work reliably.
- # shellcheck disable=3028
- if from_portage; then
- # Python's pty module is broken. For now, expect for
- # portage to have exported COLUMNS to the environment.
- set -- 0 "${COLUMNS}"
- elif _should_throttle 100; then
- test "${genfun_cols}"
- return
- elif [ "${genfun_bin_true}" ] && [ "$$" = "${BASHPID}" ]; then
- # To execute the true binary is faster than stty(1).
- "${genfun_bin_true}"
- set -- 0 "${COLUMNS}"
- else
- # This use of stty(1) is portable as of POSIX-1.2024.
- IFS=' '
- # shellcheck disable=2046
- set -- $(stty size 2>/dev/null)
- fi
- [ "$#" -eq 2 ] && is_int "$2" && [ "$2" -gt 0 ] &&
genfun_cols=$2
- }
-
- _update_columns
+ [ "$#" -eq 2 ] && is_int "$2" && [ "$2" -gt 0 ] && genfun_cols=$2
}
#