From 63c10ace1bc5d68d7d947ee91beadd452cb64d60 Mon Sep 17 00:00:00 2001
From: mattijs <m.janssens@opencfd.co.uk>
Date: Wed, 25 Jun 2008 09:31:28 +0100
Subject: [PATCH] simplification of colouring

---
 wmake/wmakeScheduler | 38 +++++++++++++++-----------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/wmake/wmakeScheduler b/wmake/wmakeScheduler
index 14f4d904028..241f2502d1a 100755
--- a/wmake/wmakeScheduler
+++ b/wmake/wmakeScheduler
@@ -137,16 +137,6 @@ done
 # is returned and not of colouring pipe.
 set -o pipefail
 
-# Define function to colour output by argument 1
-colourPipe(){
-    if [ "$1" ]; then
-        (while read line; do setterm -foreground $1; echo "$line" ; done; setterm -foreground default)
-    else
-        cat
-    fi
-}
-
-
 colourIndex=0
 
 while :
@@ -164,26 +154,28 @@ do
         do
             lockFile="$lockDir/$host:$i"
             if lockfile -r0 "$lockFile" 2>/dev/null; then
-                # Set colour
-                colour=${colours[$colourIndex]}
-                ## echo "** host=$host  colourIndex=$colourIndex  colour=$colour"
-
-                if [ "$host" = "$HOST" ]; then
-                    if [ "$colour" ]; then
-                        eval $* 2>&1 | colourPipe $colour
+                if [ "$WM_COLOURS" ]; then
+                    # Set colour
+                    colourString=`setterm -foreground ${colours[$colourIndex]}`
+
+                    if [ "$host" = "$HOST" ]; then
+                        eval $* 2>&1 | sed -e "s/^/$colourString/"
+                    elif [ -n "$JOB_ID" ]; then
+                        qrsh -inherit -v PWD $host "$rcmd"
                     else
-                        eval $*
+                        ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | sed -e "s/^/$colourString/"
                     fi
-                elif [ -n "$JOB_ID" ]; then
-                    qrsh -inherit -v PWD $host "$rcmd"
+                    retval=$?
                 else
-                    if [ "$colour" ]; then
-                        ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe $colour
+                    if [ "$host" = "$HOST" ]; then
+                        eval $*
+                    elif [ -n "$JOB_ID" ]; then
+                        qrsh -inherit -v PWD $host "$rcmd"
                     else
                         ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd"
                     fi
+                    retval=$?
                 fi
-                retval=$?
 
                 # Release lock
                 rm -f "$lockFile" 2>/dev/null
-- 
GitLab