From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sahitihi Subject: Re: Fwd: Re: Patch file for colorize module Date: Tue, 5 Jun 2018 00:21:00 +0530 Message-ID: <07c93c07-2172-6bf1-6188-88830c1d8b4c@swecha.net> References: <8ea5d026-fab9-7b12-198e-610ad7743cb2@swecha.net> <87o9hycwl6.fsf@elephly.net> <87r2mhdeap.fsf@elephly.net> <618c131c-6ba6-e525-aefc-72acca1c910f@swecha.net> <87a7suwtp7.fsf@elephly.net> <149bfb8c-22b5-797d-e88a-ca4077b0a4cc@swecha.net> <87d0xmok8e.fsf@elephly.net> <87k1rsb9ex.fsf@elephly.net> <3e099b0b-e3ec-2bbb-6d10-5b7e48c4dff6@swecha.net> <300fd917-6742-3ef1-044d-4b0f38a44250@swecha.net> <87a7sm4v5j.fsf@elephly.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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------025A2ED4437FFED51F83CFC7" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPua9-0008My-A9 for guix-devel@gnu.org; Mon, 04 Jun 2018 14:51:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPua6-00063K-8J for guix-devel@gnu.org; Mon, 04 Jun 2018 14:51:53 -0400 In-Reply-To: <87zi0a3m3t.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. --------------025A2ED4437FFED51F83CFC7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ricardo, I have made necessary changes to ui, patch file is attached. Please review changes and additionals to be added. > to apply a different colour to different parts of the strings, e.g. usi= ng blue for > the name of the build phase and green for the rest. > > You will need to use regular expressions with sufficient match groups. I have added above requirements to handle-string and used soft-port. I din't added commentary lines i will be doing that. ----- Thanks! Sahithi. --------------025A2ED4437FFED51F83CFC7 Content-Type: text/x-patch; name="0001-Added-a-soft-port-to-guix-ui-that-colorizes-strings-.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Added-a-soft-port-to-guix-ui-that-colorizes-strings-.pa"; filename*1="tch" =46rom ab1d07107b3f701b8bcaed8eab3565dc0968f20c Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Jun 2018 00:08:32 +0530 Subject: [PATCH] Added a soft port to (guix ui) that colorizes strings th= at match Regular Expressions. --- guix/ui.scm | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/guix/ui.scm b/guix/ui.scm index 80f1a4d77..3a36daadc 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -109,7 +109,8 @@ warning info guix-main - colorize-string)) + colorize-string + guix-colorful-port)) =20 ;;; Commentary: ;;; @@ -1631,4 +1632,43 @@ be reset such that subsequent output will not have= any colors in effect." str (color 'RESET))) =20 +(define target-port (current-output-port)) +=20 +(define (handle-string str) + (or (and=3D> (string-match "^(starting phase)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN))))) + + (and=3D> (string-match "^(phase)(.*) (succeeded)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN)) + (colorized-display (match:substring m 3) '(BLUE)) + (colorized-display (match:substring m 4) '(GREEN))))) + + (and=3D> (string-match "^(phase)(.*) (failed)(.*)" str) + (lambda (m) + (string-append + (colorized-display (match:substring m 1) '(BLUE)) + (colorized-display (match:substring m 2) '(GREEN)) + (colorized-display (match:substring m 3) '(BLUE)) + (colorized-display (match:substring m 4) '(GREEN))))) + + ;; Didn=E2=80=99t match, so return unmodified string. + str) + (display str target-port)) + +(define guix-colorful-port + (make-soft-port + (vector + (lambda (c) (write c target-port)) + handle-string + (lambda () (display "." target-port)) + (lambda () (char-upcase (read-char))) + (lambda () (display "@" target-port))) + "rw")) + ;;; ui.scm ends here --=20 2.11.0 --------------025A2ED4437FFED51F83CFC7--