[Lunar-commits] <lunar> Progressbar/spinner for compile logs.

Auke Kok sofar at foo-projects.org
Wed Jun 15 07:36:11 CEST 2011


commit 7aa8920c328586ec8555a48e64324580c940f6e9
Author: Auke Kok <sofar at foo-projects.org>
Date:   Tue Jun 14 22:36:11 2011 -0700

    Progressbar/spinner for compile logs.
    
    Enable the spinner as follows:
    
    	# lunar set VOYEUR pc
    
    The spinner works as follows:
    - estimates the compile progress based on the length of the previous compile log
    - paints a progress bar with % number
    - if no previous compile log found, displays a spinner!
---
 var/lib/lunar/functions/logging.lunar |   46 +++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/var/lib/lunar/functions/logging.lunar b/var/lib/lunar/functions/logging.lunar
index 469edcc..e1f8704 100644
--- a/var/lib/lunar/functions/logging.lunar
+++ b/var/lib/lunar/functions/logging.lunar
@@ -36,11 +36,57 @@ stop_logging() {
 }
 
 
+progress() {
+  local OLDLOG OLDSZ S PC
+  OLDLOG=$(ls -1d $COMPILE_LOGS/$MODULE-*.bz2 2>&- | head -n 1)
+  if [[ -f $OLDLOG ]]; then
+    X="############################################################"
+    Y="                                                            "
+    OLDSZ=$(bzcat $OLDLOG | wc -c)
+    while true ; do
+      read -t 2 LINE
+      STATUS=$?
+      if [ $STATUS -gt 128 ]; then
+        sleep 2
+      elif [ $STATUS -eq 1 ]; then
+        echo -ne "\r [${X:0:60}] (100%)"
+        exit
+      fi
+      (( S += ${#LINE} ))
+      PC=$((S * 100 / OLDSZ))
+      L=$((S * 60 / OLDSZ))
+      if [[ $L -gt 60 ]]; then
+        ((L=60))
+      fi
+      echo -ne "\r [${X:0:$L}${Y:0:$((60 - L))}] ($PC%)\r"
+    done
+  else
+    SPINNER="/-\|"
+    # spinerrrrrr!!!!
+    while true ; do
+      read -t 2 LINE
+      STATUS=$?
+      if [ $STATUS -gt 128 ]; then
+        sleep 2
+      elif [ $STATUS -eq 1 ]; then
+        exit
+      fi
+      ((C++))
+      if [[ $C -gt ${#SPINNER} ]]; then
+        C=0
+      fi
+      echo -en "\r [${SPINNER:$C:1}]\r"
+    done
+  fi
+}
+
+
 activate_voyeur()  {
   debug_msg "activate_voyeur ($@)"
   if [ -z "$SILENT" ] ; then
     case $VOYEUR in
       on) tee -a $C_LOG < $C_FIFO              & ;;
+      p*) tee -a $C_LOG < $C_FIFO | progress   & ;;
        *) tee -a $C_LOG < $C_FIFO >/dev/null   & ;;
     esac
   else


More information about the Lunar-commits mailing list