From 3498c2a1b387fb83a960e6ed1faaa3e5fd68fa50 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Mon, 20 Jun 2011 19:34:07 +0200 Subject: status: adjust number of columns after loading modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case loading modules enables a frambuffer with higher resolution than the standard 80 columns, we recalculate the number of columns after all modules have been loaded. Original-patch-by: Aaron Griffin Original-patch-by: Søren Poulsen Signed-off-by: Tom Gundersen --- functions | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'functions') diff --git a/functions b/functions index d94a9ef..d0747ba 100644 --- a/functions +++ b/functions @@ -4,26 +4,40 @@ # width: -STAT_COL=80 -if [[ ! -t 1 ]]; then - USECOLOR="" -elif [[ -t 0 ]]; then - # stty will fail when stdin isn't a terminal - STAT_COL="$(/bin/stty size)" - # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" -elif /bin/tput cols &>/dev/null; then - # is /usr/share/terminfo already mounted, and TERM recognized? - STAT_COL=$(/bin/tput cols) -fi -if ((STAT_COL==0)); then - # if output was 0 (serial console), set default width to 80 +calc_columns () { STAT_COL=80 - USECOLOR="" -fi + if [[ ! -t 1 ]]; then + USECOLOR="" + elif [[ -t 0 ]]; then + # stty will fail when stdin isn't a terminal + STAT_COL="$(/bin/stty size)" + # stty gives "rows cols"; strip the rows number, we just want columns + STAT_COL="${STAT_COL##* }" + elif /bin/tput cols &>/dev/null; then + # is /usr/share/terminfo already mounted, and TERM recognized? + STAT_COL=$(/bin/tput cols) + fi + if ((STAT_COL==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)) + + if [[ -t 1 ]]; then + SAVE_POSITION="\e[s" + RESTORE_POSITION="\e[u" + DEL_TEXT="\e[$(($STAT_COL+4))G" + else + SAVE_POSITION="" + RESTORE_POSITION="" + DEL_TEXT="" + fi +} -# we use 13 characters for our own stuff -STAT_COL=$(($STAT_COL - 13)) +calc_columns # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" @@ -76,16 +90,6 @@ if [[ $USECOLOR =~ yes|YES ]]; then fi fi -if [[ -t 1 ]]; then - SAVE_POSITION="\e[s" - RESTORE_POSITION="\e[u" - DEL_TEXT="\e[$(($STAT_COL+4))G" -else - SAVE_POSITION="" - RESTORE_POSITION="" - DEL_TEXT="" -fi - # prefixes: PREFIX_REG="::" -- cgit v1.2.3