From 0c978ca3f48c2417f47bb1e87b9a14867c93ed89 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Fri, 14 Aug 2009 13:07:31 -0400 Subject: [PATCH] Fix stty/tput usage for columns again Cleans up double application of earlier fixes for this issue. Instead of calling $(tput cols 2>/dev/null), we now try tput cols silently to see whether it complains. If not, then we call $(tput cols) with no redirection of stderr. This way, we can get results other than 80. eliminate color when stdout is not terminal Signed-off-by: Jim Pryor --- functions | 44 ++++++++++++++++++-------------------------- 1 files changed, 18 insertions(+), 26 deletions(-) diff --git a/functions b/functions index 0f333d4..72e916a 100644 --- a/functions +++ b/functions @@ -5,36 +5,28 @@ # width: STAT_COL=80 -if [ -t 1 ]; then - # stty will fail when stdin isn't a terminal (but we're in this block, so stdout is) - if [ -t 0 ]; then - STAT_COL="$(/bin/stty size)" - # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" - else - # tput will fail at boot time if /usr/share/terminfo isn't yet mounted - # or TERM is otherwise unrecognized - STAT_COL="$(/bin/tput cols 2>/dev/null)" - fi - if [ "0$STAT_COL" -eq 0 ]; then - # if output was 0 (serial console), set default width to 80 - USECOLOR="" - STAT_COL=80 - fi -else +if [ ! -t 1 ]; then USECOLOR="" - STAT_COL=80 -fi -if [ -t 1 ]; then - STAT_COL=$(/bin/stty size) - # strip the rows number, we just want columns - STAT_COL=${STAT_COL##* } - if [ "$STAT_COL" = "0" ]; then - # if output was 0 (serial console), set default width to 80 - STAT_COL=80 +# stty will fail when stdin isn't a terminal +elif [ -t 0 ]; then + STAT_COL="$(/bin/stty size)" + # stty gives "rows cols"; strip the rows number, we just want columns + STAT_COL="${STAT_COL##* }" + +else + # is /usr/share/terminfo already mounted, and TERM recognized? + /bin/tput cols &>/dev/null + if [ $? -eq 0 ]; then + STAT_COL=$(/bin/tput cols) fi fi +if [ "0$STAT_COL" -eq 0 ]; then + # if output was 0 (serial console), set default width to 80 + STAT_COL=80 + USECOLOR="" +fi + # we use 13 characters for our own stuff STAT_COL=$(($STAT_COL - 13)) -- 1.6.4