]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - make.sh
make.sh: Continue producing nice output after screen has been resized
[people/pmueller/ipfire-2.x.git] / make.sh
diff --git a/make.sh b/make.sh
index 44516af73685f08d1c80b39c5510aa7449d11879..22724aa87235d924be3250a69736118e094b3903 100755 (executable)
--- 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"