From 401a1edc5688733821e69d885132025703944823 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 28 Nov 2017 17:22:23 +0000 Subject: [PATCH] make.sh: Continue producing nice output after screen has been resized Signed-off-by: Michael Tremer --- make.sh | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/make.sh b/make.sh index 44516af736..22724aa872 100755 --- a/make.sh +++ b/make.sh @@ -52,27 +52,33 @@ else INTERACTIVE=false fi -## Screen Dimentions -# Find current screen size -if [ -z "${COLUMNS}" ]; then - COLUMNS=$(stty size) - COLUMNS=${COLUMNS##* } -fi +# Sets or adjusts pretty formatting variables +resize_terminal() { + ## Screen Dimentions + # Find current screen size + COLUMNS=$(tput cols) + + # When using remote connections, such as a serial port, stty size returns 0 + if ! ${INTERACTIVE} || [ "${COLUMNS}" = "0" ]; then + COLUMNS=80 + fi -# When using remote connections, such as a serial port, stty size returns 0 -if ! ${INTERACTIVE} || [ "${COLUMNS}" = "0" ]; then - COLUMNS=80 -fi + # Measurements for positioning result messages + OPTIONS_WIDTH=20 + TIME_WIDTH=12 + STATUS_WIDTH=8 + NAME_WIDTH=$(( COLUMNS - OPTIONS_WIDTH - TIME_WIDTH - STATUS_WIDTH )) + LINE_WIDTH=$(( COLUMNS - STATUS_WIDTH )) + + TIME_COL=$(( COLUMNS - TIME_WIDTH - STATUS_WIDTH )) + STATUS_COL=$(( COLUMNS - STATUS_WIDTH )) +} -## Measurements for positioning result messages -OPTIONS_WIDTH=20 -TIME_WIDTH=12 -STATUS_WIDTH=8 -NAME_WIDTH=$(( COLUMNS - OPTIONS_WIDTH - TIME_WIDTH - STATUS_WIDTH )) -LINE_WIDTH=$(( COLUMNS - STATUS_WIDTH )) +# Initially setup terminal +resize_terminal -TIME_COL=$(( COLUMNS - TIME_WIDTH - STATUS_WIDTH )) -STATUS_COL=$(( COLUMNS - STATUS_WIDTH )) +# Call resize_terminal when terminal is being resized +trap "resize_terminal" WINCH # Define color for messages BOLD="\\033[1;39m" -- 2.39.2