guix-commits
[Top][All Lists]
Advanced

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

03/07: weather: Colorize the output.


From: guix-commits
Subject: 03/07: weather: Colorize the output.
Date: Fri, 1 Apr 2022 12:10:58 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 2a363bb5d38ebe3d354ccf7ee5953e8266822dad
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Apr 1 13:41:52 2022 +0200

    weather: Colorize the output.
    
    * guix/colors.scm (coloring-procedure): Export.
    * guix/scripts/weather.scm (report-server-coverage): Highlight the
    server name and colorize the availability ratio.
---
 guix/colors.scm          |  1 +
 guix/scripts/weather.scm | 19 ++++++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/guix/colors.scm b/guix/colors.scm
index ae0a583d94..567c822c73 100644
--- a/guix/colors.scm
+++ b/guix/colors.scm
@@ -29,6 +29,7 @@
   #:export (color
             color?
 
+            coloring-procedure
             colorize-string
             highlight
             highlight/warn
diff --git a/guix/scripts/weather.scm b/guix/scripts/weather.scm
index 60a697d1ac..adba614b8c 100644
--- a/guix/scripts/weather.scm
+++ b/guix/scripts/weather.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2017-2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
@@ -31,6 +31,7 @@
   #:use-module (guix store)
   #:use-module (guix grafts)
   #:use-module (guix gexp)
+  #:use-module (guix colors)
   #:use-module ((guix build syscalls) #:select (terminal-columns))
   #:use-module ((guix build utils) #:select (every*))
   #:use-module (guix substitutes)
@@ -203,7 +204,7 @@ In case ITEMS is an empty list, return 1 instead."
                     #:make-progress-reporter
                     (lambda* (total #:key url #:allow-other-keys)
                       (progress-reporter/bar total)))))
-    (format #t "~a~%" server)
+    (format #t (highlight "~a~%") server)
     (let ((obtained  (length narinfos))
           (requested (length items))
           (missing   (lset-difference string=?
@@ -215,9 +216,17 @@ In case ITEMS is an empty list, return 1 instead."
           (time      (+ (time-second time)
                         (/ (time-nanosecond time) 1e9))))
       (when (> requested 0)
-        (format #t (G_ "  ~,1f% substitutes available (~h out of ~h)~%")
-                (* 100. (/ obtained requested 1.))
-                obtained requested))
+        (let* ((ratio    (/ obtained requested 1.))
+               (colorize (cond ((> ratio 0.80)
+                                (coloring-procedure (color BOLD GREEN)))
+                               ((< ratio 0.50)
+                                (coloring-procedure (color BOLD RED)))
+                               (else
+                                highlight))))
+          (format #t
+                  (colorize (G_ "  ~,1f% substitutes available (~h out of 
~h)~%"))
+                  (* 100. ratio)
+                  obtained requested)))
       (let ((total (/ (reduce + 0 sizes) MiB)))
         (match (length sizes)
           ((? zero?)



reply via email to

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