Recently Written · git

clic

MIRROR ONLY Gopher client with pretty colours in Common Lisp

git clone https://github.com/equwal/clic

Log | Files | Refs


commit 1f6eeef4e3b769c19b558f9218d618b59383a54d
Solene Rapenne <solene@perso.pw>
2018-08-13 12:33:37 +0200

Add current page size in Kb and the whole bandwidth usage at the end

 clic.lisp | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/clic.lisp b/clic.lisp
index ea3dd33..8a48eaa 100644
--- a/clic.lisp
+++ b/clic.lisp
@@ -63,6 +63,10 @@
 ;;; array of lines of last menu
 (defparameter *previous-buffer* nil)
 
+;;; bandwidth usage counter
+(defparameter *total-bandwidth-in* 0)
+(defparameter *last-bandwidth-in* 0)
+
 ;;; a list containing the last viewed pages
 (defparameter *history*   '())
 
@@ -303,6 +307,7 @@
                     :fill-pointer 0
                     :initial-element nil
                     :adjustable t))
+  (setf *last-bandwidth-in* 0)
 
   (let ((real-time (get-internal-real-time)))
     ;; we prepare informations about the connection
@@ -319,11 +324,15 @@
         count line into lines
         while line
         do
+	;; count bandwidth usage
+        (incf *total-bandwidth-in* (length line))
+        (incf *last-bandwidth-in* (length line))
         ;; increase array size if needed
           (when (= lines (- (array-total-size *buffer*) 1))
             (adjust-array *buffer* (+ 200 (array-total-size *buffer*))))
           (vector-push line *buffer*)))
 
+
     ;; we store the duration of the connection
     (setf *duration* (float (/ (- (get-internal-real-time) real-time)
                                internal-time-units-per-second)))))
@@ -707,13 +716,14 @@
 
 (defun display-prompt()
   (let ((last-page (car *history*)))
-    (format t "~agopher://~a:~a/~a~a (~as) / (p)rev (r)edisplay (h)istory : "
+    (format t "~agopher://~a:~a/~a~a (~as, ~aKb) / (p)rev (r)edisplay (h)istory : "
             (if *kiosk-mode* "KIOSK " "")
             (location-host last-page)
             (location-port last-page)
             (location-type last-page)
             (location-uri last-page)
-            *duration*))
+            *duration*
+	    (floor (/ *last-bandwidth-in* 1024.0))))
   (force-output))
 
 (defun shell()
@@ -769,7 +779,8 @@
                 ;; to look it here
                 (when (not (eq 'end (visit destination)))
                   ;; we continue to the shell if we are in a terminal
-                  (shell))))
+                  (shell)))
+	    (format t "~a kB in.~%" (floor (/ *total-bandwidth-in* 1024.0))))
           (pipe-to-stdout destination)))))
 
 ;; we allow ecl to use a new kind of argument