From 2a363bb5d38ebe3d354ccf7ee5953e8266822dad Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 1 Apr 2022 13:41:52 +0200 Subject: 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(-) (limited to 'guix') 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 +;;; Copyright © 2017-2022 Ludovic Courtès ;;; Copyright © 2017 Ricardo Wurmus ;;; Copyright © 2018 Kyle Meyer ;;; Copyright © 2020 Simon Tournier @@ -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?) -- cgit v1.2.3