stumpwm-devel
[Top][All Lists]
Advanced

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

[STUMP] [PATCH] Bars for the net monitor.


From: Jose Antonio Ortega Ruiz
Subject: [STUMP] [PATCH] Bars for the net monitor.
Date: Mon, 22 Mar 2010 20:58:01 +0100

---
 contrib/net.lisp |   89 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 76 insertions(+), 13 deletions(-)

diff --git a/contrib/net.lisp b/contrib/net.lisp
index a86569c..1c23e78 100644
--- a/contrib/net.lisp
+++ b/contrib/net.lisp
@@ -28,7 +28,13 @@
 ;;;
 ;;; In your ~/.stumpwmrc
 ;;;
-;;; Then you can use "%l" in your mode line format.
+;;; Then you can use "%l" in your mode line format. The fields shown are
+;;; controlled by *net-modeline-fmt*, which can include %d for the device
+;;; name, %r and %t for reception and transmission speeds, and %R and %T
+;;; for bars depicting those speeds. The bars' width, full and empty
+;;; characters and scale can be fine-tuned by modifying the exported
+;;; variables *net-bar-width*, *net-bar-full*, *net-bar-empty* and
+;;; *net-bar-scale*.
 ;;;
 ;;; NOTES:
 ;;;
@@ -36,7 +42,9 @@
 
 (defpackage :stumpwm.contrib.net
   (:use :common-lisp :stumpwm :cl-ppcre)
-  (:export #:*net-device*))
+  (:export #:*net-device* #:*net-modeline-fmt*
+           #:*net-bar-scale* #:*net-bar-width*
+           #:*net-bar-full* #:*net-bar-empty*))
 
 (in-package :stumpwm.contrib.net)
 
@@ -151,16 +159,71 @@ For the second case rescans route table every minute."
       (list (round (/ rx-s t-s))
            (round (/ tx-s t-s)))))
 
+(defvar *net-modeline-fmt* "%d: %r/%t"
+  "The format of the net modeline display.
+
address@hidden @asis
address@hidden %%
+A literal '%'
address@hidden %d
+The device name
address@hidden %r
+Receiving speed
address@hidden %t
+Transmitting speed
address@hidden %R
+Receiving speed bar
address@hidden %T
+Transmitting speed bar")
+
+(defvar *net-bar-width* 10)
+(defvar *net-bar-full* #\#)
+(defvar *net-bar-empty* #\:)
+(defvar *net-bar-scale* 1e5)
+
+(defvar *net-modeline-formatters*
+  '((#\d net-get-device)
+    (#\r net-get-rx)
+    (#\t net-get-tx)
+    (#\R net-get-rx-bar)
+    (#\T net-get-tx-bar)))
+
+(defun net-get-rx (rx tx)
+  (declare (ignore tx))
+  (format-net-speed rx))
+
+(defun net-get-tx (rx tx)
+  (declare (ignore rx))
+  (format-net-speed tx))
+
+(defun net-get-rx-bar (rx tx)
+  (declare (ignore tx))
+  (format-net-bar rx))
+
+(defun net-get-tx-bar (rx tx)
+  (declare (ignore rx))
+  (format-net-bar tx))
+
+(defun net-get-device (rx tx)
+  (declare (ignore rx tx))
+  (format nil "~A" (net-device)))
+
+(defun format-net-speed (x)
+  (if (>= (/ x 1e6) 0.1)
+      (format nil "~5,2Fm" (/ x 1e6))
+      (format nil "~5,2Fk" (/ x 1e3))))
+
+(defun format-net-bar (s)
+  (let ((s (if (zerop s) 0
+               (+ 0.8 (/ (log (/ s *net-bar-scale*) 10) *net-bar-width*)))))
+    (stumpwm::bar (* 100 s) *net-bar-width* *net-bar-full* *net-bar-empty*)))
+
 (defun fmt-net-usage (ml)
-  "Returns a string representing the current network activity."
+  "Returns a string representing the current network activity.
+Uses '*NET-MODELINE-FMT*' for formatting."
   (declare (ignore ml))
-  (let ((net (net-usage))
-       dn up)
-    (defun kbmb (x y)
-      (if (>= (/ x 1e6) y)
-         (list (/ x 1e6) "m")
-         (list (/ x 1e3) "k")))
-    (setq dn (kbmb (car net) 0.1)
-         up (kbmb (cadr net) 0.1))
-    (format nil "~A: ~5,2F~A/~5,2F~A " (net-device)
-           (car dn) (cadr dn) (car up) (cadr up))))
+  (let* ((net (net-usage)))
+    (stumpwm::format-expand *net-modeline-formatters*
+                            *net-modeline-fmt*
+                            (car net) (cadr net))))
+
-- 
1.7.0.2





reply via email to

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