diff options
author | Jim Pryor <profjim@jimpryor.net> | 2009-08-14 13:07:31 -0400 |
---|---|---|
committer | Aaron Griffin <aaronmgriffin@gmail.com> | 2009-09-24 14:36:16 -0700 |
commit | c3276e250c88173f36ddd50bc6a6c4feeb7409cb (patch) | |
tree | 04a9232462a66f761d1219621bbeb19b6e8b72a8 | |
parent | 65f4102d48726afa4324d789551e7a74c806a590 (diff) | |
download | initscripts-c3276e250c88173f36ddd50bc6a6c4feeb7409cb.tar.xz |
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 <profjim@jimpryor.net>
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
-rw-r--r-- | functions | 44 |
1 files changed, 18 insertions, 26 deletions
@@ -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)) |