stumpwm-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[STUMP] [PATCH] Modified bar-zone-color to accept customized limits, "


From: John Li
Subject: [STUMP] [PATCH] Modified bar-zone-color to accept customized limits, "reverse" option.
Date: Fri, 18 Jul 2008 01:13:59 -0400
User-agent: Mutt/1.5.18 (2008-05-17)

---

This includes the patch I sent on July 16, "Add \"reverse\" option to
bar-zone-color, modify battery.lisp to use it.", and adds the option
for custom limits. This lets you use it for more than just CPU time
(e.g., memory usage, wifi signal, CPU temperature).

Maybe this makes it too general to have it still be named
bar-zone-color?

 contrib/battery.lisp |    3 ++-
 mode-line.lisp       |   20 ++++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/contrib/battery.lisp b/contrib/battery.lisp
index aff4180..2607dad 100644
--- a/contrib/battery.lisp
+++ b/contrib/battery.lisp
@@ -93,7 +93,8 @@
   (declare (ignore ml))
   (current-battery-charge)
   (if *bat-state*
-      (format nil "BAT: ~D%~A"
+      (format nil "BAT: ^[~A~D%^]~A"
+              (bar-zone-color *bat-remain* 50 30 10 t)
               *bat-remain*
               (if *bat-remain-time*
                   (format nil " (~2,'0d:~2,'0d) ~A"  (car *bat-remain-time*) 
(cadr *bat-remain-time*) *bat-state*) "")) "no battery"))
diff --git a/mode-line.lisp b/mode-line.lisp
index 9f8e940..5b24671 100644
--- a/mode-line.lisp
+++ b/mode-line.lisp
@@ -178,16 +178,16 @@ timer.")
 (defvar *bar-hi-color* "^B^3*")
 (defvar *bar-crit-color* "^B^1*")
 
-(defun bar-zone-color (percent)
-  (concatenate 'string
-               (cond
-                 ((>= percent 90)
-                  *bar-crit-color*)
-                 ((>= percent 50)
-                  *bar-hi-color*)
-                 ((>= percent 20)
-                  *bar-med-color*)
-                 (t ""))))
+(defun bar-zone-color (amount &optional (med 20) (hi 50) (crit 90) reverse)
+  "Return a color command based on the magnitude of the argument. If
+the limits for the levels aren't specified, they default to sensible
+values for a percentage. With reverse, lower numbers are more
+critical."
+  (labels ((past (n) (funcall (if reverse #'<= #'>=) amount n)))
+    (cond ((past crit) *bar-crit-color*)
+          ((past hi) *bar-hi-color*)
+          ((past med) *bar-med-color*)
+          (t ""))))
 
 (defun repeat (n char)
  (make-string n :initial-element char))
-- 
1.5.6





reply via email to

[Prev in Thread] Current Thread [Next in Thread]