From f20da126fd4c4cb234cdafa15f0f35ecf1f24e84 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. Signed-off-by: Jim Pryor --- functions | 40 ++++++++++++++-------------------------- 1 files changed, 14 insertions(+), 26 deletions(-) diff --git a/functions b/functions index 0f333d4..254e52d 100644 --- a/functions +++ b/functions @@ -5,36 +5,24 @@ # 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 +# stty will fail when stdin isn't a terminal +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 - USECOLOR="" + # 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 -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 - fi -fi # we use 13 characters for our own stuff STAT_COL=$(($STAT_COL - 13)) -- 1.6.4