From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sahitihi Subject: Re: Fwd: Re: Patch file for colorize module Date: Sat, 9 Jun 2018 23:38:55 +0530 Message-ID: References: <8ea5d026-fab9-7b12-198e-610ad7743cb2@swecha.net> <3d5eca09-7730-bd38-265b-7942d0ea16ed@swecha.net> <878t864i59.fsf@elephly.net> <87o9gwpcmx.fsf@elephly.net> <2f71be8d-c672-c66a-0b16-bc3abc748754@swecha.net> <877enjpquf.fsf@elephly.net> <557b30de-5aa2-113f-7e90-a4a23e86bb07@swecha.net> <87602zbrcc.fsf@elephly.net> <328742c6-f96f-74b8-68ef-3b165a6199aa@swecha.net> <87zi0a3m3t.fsf@elephly.net> <07c93c07-2172-6bf1-6188-88830c1d8b4c@swecha.net> <87o9gpyq4t.fsf@elephly.net> <91773c8b-3072-2a82-dca3-cbeb5adf826d@swecha.net> <87fu1zznl3.fsf@elephly.net> <87bmcnzjsp.fsf@elephly.net> <18408eca-ad0b-111a-0ef6-ab452c9ca89c@swecha.net> <878t7ryxvf.fsf@elephly.net> <02e1a59a-ebc1-dfce-e1d6-22e97e742214@swecha.net> <874lifypeb.fsf@elephly.net> <648f81fc-0607-2c3b-f9a3-ca3b29cd637b@swecha.net> <87bmck22uz.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------3F07086BD69A47B8558236DE" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRiJA-00010r-Sz for guix-devel@gnu.org; Sat, 09 Jun 2018 14:09:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRiJ5-0000QB-GM for guix-devel@gnu.org; Sat, 09 Jun 2018 14:09:48 -0400 In-Reply-To: <87bmck22uz.fsf@elephly.net> Content-Language: en-US List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ricardo Wurmus Cc: guix-devel This is a multi-part message in MIME format. --------------3F07086BD69A47B8558236DE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ricardo, When I used "(colorize-string "hello" '(GREEN))" in REPL that gave me a error unbound variable colorize-string When i used the same in attached file this gave me a colorless output However when I tried with "(colorize-string "hello" 'GREEN)" in same file this gave me colored output but in REPL still a unbound-variable. So, I tried changing "(GREEN)" to "GREEN" in ui.scm but resulted with a colorless output. > I found the error already, but I=E2=80=99m sure you can too. Here=E2=80= =99s a hint: > play around with =E2=80=9C(colorize-string "hello" '(GREEN))=E2=80=9D. = Does this look > right? If not, why is that? Look closely at the definition of > =E2=80=9Ccolorize-string=E2=80=9D. What arguments does it expect? How= are arguments > bound to variables? How many arguments does =E2=80=9Ccolorize-string=E2= =80=9D accept? > Are you really sure about that=E2=80=A6? Attached file contains the details can you please review it once. --- Thanks! Sahithi --------------3F07086BD69A47B8558236DE Content-Type: text/x-scheme; name="term ansi-color.scm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="term ansi-color.scm" (define-module (term ansi-color) #:export (color colorize-string) #:use-module (srfi srfi-1)) ; for 'remove' (define ansi-color-tables `((CLEAR . "0") (RESET . "0") (BOLD . "1") (DARK . "2") (UNDERLINE . "4") (UNDERSCORE . "4") (BLINK . "5") (REVERSE . "6") (CONCEALED . "8") (BLACK . "30") (RED . "31") (GREEN . "32") (YELLOW . "33") (BLUE . "34") (MAGENTA . "35") (CYAN . "36") (WHITE . "37") (ON-BLACK . "40") (ON-RED . "41") (ON-GREEN . "42") (ON-YELLOW . "43") (ON-BLUE . "44") (ON-MAGENTA . "45") (ON-CYAN . "46") (ON-WHITE . "47"))) (define (color . lst) "The allowed values for the attributes are listed below. Unknown attributes are ignored. @table @asis @item Reset Attributes @samp{CLEAR} and @samp{RESET} are allowed and equivalent. @item Non-Color Attributes @samp{BOLD} makes text bold, and @samp{DARK} reverses this. @samp{UNDERLINE} and @samp{UNDERSCORE} are equivalent. @samp{BLINK} makes the text blink. @samp{REVERSE} invokes reverse video. @samp{CONCEALED} hides output (as for getting passwords, etc.). @item Foregrond Color Attributes @samp{BLACK}, @samp{RED}, @samp{GREEN}, @samp{YELLOW}, @samp{BLUE}, @samp{MAGENTA}, @samp{CYAN}, @samp{WHITE} @item Background Color Attributes @samp{ON-BLACK}, @samp{ON-RED}, @samp{ON-GREEN}, @samp{ON-YELLOW}, @samp{ON-BLUE}, @samp{ON-MAGENTA}, @samp{ON-CYAN}, @samp{ON-WHITE} @end table" (let ((color-list=20 (remove not=20 (map (lambda (color) (assq-ref ansi-color-tables color))= lst)))) (if (null? color-list) "" (string-append=20 (string #\esc #\[) (string-join color-list ";" 'infix) "m")))) =20 (define (colorize-string str . color-list) "Returns a copy of @var{str} colorized using ANSI escape sequences according to the attributes specified in @var{color-list}. At the end of the returned string, the color attributes will be reset such that subsequent output will not have any colors in effect. The allowed values for the attributes are listed in the documentation for the @code{color} function." (string-append (apply color color-list) str (color 'RESET))) (display (colorize-string "Hello!\n" 'RED)) (for-each display (list (color 'RED) "Hello!" (color 'RESET))) --------------3F07086BD69A47B8558236DE--