From ab174e16b5832b1ff978740e6b4c48cf194c0a96 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 19 Jun 2022 22:53:52 +0200 Subject: challenge: Colorize output. * guix/scripts/challenge.scm (good-news, bad-news): New procedures. (summarize-report, summarize-report-list): Use them and 'highlight'. --- guix/scripts/challenge.scm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/guix/scripts/challenge.scm b/guix/scripts/challenge.scm index 96ffe53a85..5c0f837d13 100644 --- a/guix/scripts/challenge.scm +++ b/guix/scripts/challenge.scm @@ -18,6 +18,7 @@ (define-module (guix scripts challenge) #:use-module (guix ui) + #:use-module (guix colors) #:use-module (guix scripts) #:use-module (guix store) #:use-module (guix utils) @@ -388,6 +389,11 @@ COMPARISON-REPORT." (append command (list directory1 directory2)))))) +(define good-news + (coloring-procedure (color BOLD GREEN))) +(define bad-news + (coloring-procedure (color BOLD RED))) + (define* (summarize-report comparison-report #:key (report-differences (const #f)) @@ -410,7 +416,7 @@ with COMPARISON-REPORT." (match comparison-report (($ item 'mismatch local (narinfos ...)) - (report (G_ "~a contents differ:~%") item) + (report (bad-news (G_ "~a contents differ:~%")) item) (report-hashes item local narinfos) (report-differences comparison-report)) (($ item 'inconclusive #f narinfos) @@ -419,7 +425,7 @@ with COMPARISON-REPORT." (warning (G_ "could not challenge '~a': no substitutes~%") item)) (($ item 'match local (narinfos ...)) (when verbose? - (report (G_ "~a contents match:~%") item) + (report (good-news (G_ "~a contents match:~%")) item) (report-hashes item local narinfos))))) (define (summarize-report-list reports) @@ -428,10 +434,11 @@ with COMPARISON-REPORT." (inconclusive (count comparison-report-inconclusive? reports)) (matches (count comparison-report-match? reports)) (discrepancies (count comparison-report-mismatch? reports))) - (report (G_ "~h store items were analyzed:~%") total) - (report (G_ " - ~h (~,1f%) were identical~%") + (report (highlight (G_ "~h store items were analyzed:~%")) total) + (report (highlight (G_ " - ~h (~,1f%) were identical~%")) matches (* 100. (/ matches total))) - (report (G_ " - ~h (~,1f%) differed~%") + (report ((if (zero? discrepancies) good-news bad-news) + (G_ " - ~h (~,1f%) differed~%")) discrepancies (* 100. (/ discrepancies total))) (report (G_ " - ~h (~,1f%) were inconclusive~%") inconclusive (* 100. (/ inconclusive total))))) -- cgit v1.2.3