me
/
guix
Archived
1
0
Fork 0

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.
master
Ludovic Courtès 2022-04-01 13:41:52 +02:00
parent c1093dc7a6
commit 2a363bb5d3
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 15 additions and 5 deletions

View File

@ -29,6 +29,7 @@
#:export (color
color?
coloring-procedure
colorize-string
highlight
highlight/warn

View File

@ -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?)