>From 64691615468bbb3e4b9e4bb2322a48c4b6a25d6d Mon Sep 17 00:00:00 2001 From: root
Date: Sat, 26 May 2018 23:28:19 +0530 Subject: [PATCH] ui: Add support for colorization. * guix/ui.scm (color-table): New variable. (colorize-string): New procedure. --- guix/ui.scm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 20fbf761f..efbcbc88b 100755 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -9,7 +9,7 @@ ;;; Copyright © 2015, 2016 Mathieu Lirzin ;;; Copyright © 2016 Roel Janssen ;;; Copyright © 2016 Benz Schenk -;;; Copyright © 2013,2014 Free Software Foundation, Inc. +;;; Copyright © 2013, 2014 Free Software Foundation, Inc. ;;; Copyright © 2018 Sahithi Yarlagadda ;;; ;;; This file is part of GNU Guix. @@ -109,7 +109,6 @@ warning info guix-main - color colorize-string)) ;;; Commentary: @@ -1582,7 +1581,7 @@ and signal handling has already been set up." (initialize-guix) (apply run-guix args)) -(define ansi-color-tables +(define color-table `((CLEAR . "0") (RESET . "0") (BOLD . "1") @@ -1610,9 +1609,11 @@ and signal handling has already been set up." (ON-WHITE . "47"))) (define (color . lst) + "Returns a string containing the ANSI escape sequence for +producing the requested set of attributes. Unknown attributes are ignored." (let ((color-list (remove not - (map (lambda (color) (assq-ref ansi-color-tables color)) + (map (lambda (color) (assq-ref color-table color)) lst)))) (if (null? color-list) "" @@ -1626,5 +1627,9 @@ and signal handling has already been set up." (apply color color-list) str (color 'RESET))) + "Returns a copy of @var{str} colorized using ANSI +escape sequences according to the attributes. At the end of the returned string, the color +attributes will be reset such that subsequent output will not +have any colors in effect." ;;; ui.scm ends here -- 2.11.0