From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sahitihi Subject: Re: Fwd: Re: Patch file for colorize module Date: Sat, 16 Jun 2018 01:46:45 +0530 Message-ID: <564233bd-9511-7f84-3350-6a3a905534a8@swecha.net> References: <8ea5d026-fab9-7b12-198e-610ad7743cb2@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> <8736xv1xvq.fsf@elephly.net> <64dfaf0c-3bcf-7b76-5831-b1c41d3f5563@swecha.net> <877en4ccut.fsf@elephly.net> <2b03fcec-c2d8-0604-156c-70fe7643a6cb@swecha.net> <87zhzzbqn6.fsf@elephly.net> <8f509759-c798-a150-bf5a-9b13cd07ac5b@swecha.net> <87lgbibir5.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F37A24FBB3C4871FCB04B3D6" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTvA8-0001f3-4I for guix-devel@gnu.org; Fri, 15 Jun 2018 16:17:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTvA4-0002aY-Qw for guix-devel@gnu.org; Fri, 15 Jun 2018 16:17:36 -0400 In-Reply-To: <87lgbibir5.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. --------------F37A24FBB3C4871FCB04B3D6 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ricardo, I have fixed the errors mentioned bellow, Please do check and notify me for further modifications. >>> The next steps are to fix the errors in the regular expressions that >>> swallow certain space characters and to re-read the documentation of >>> =E2=80=9Cmake-soft-port=E2=80=9D to make sure that the procedures in = the vector behave >>> as they should. >> I will update back once i am through with it. I have added the comment lines. Patch file is attached. I applied indent script please do not worry about that. :-) > After reading the documentation for =E2=80=9Cmake-soft-port=E2=80=9D ag= ain, I recommend > adding very short comments above each of the procedures in the vector t= o > explain what they are intended to do. > Please do inform other modifications I have to do and next tasks to proceed further. --- Thanks!! Sahithi. --------------F37A24FBB3C4871FCB04B3D6 Content-Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-guix-Add-coloring-soft-port.patch" =46rom 2d4a335d0262e59784912b6cd922ae9283f17cb4 Mon Sep 17 00:00:00 2001 From: Sahithi Yarlagadda Date: Wed, 13 Jun 2018 02:08:27 +0530 Subject: [PATCH] guix: Add coloring soft port. * guix/ui.scm (handle-string): New procedures. (colorful-build-output-port): New variable. guix: Added colorful-build-output-port to build.scm instead of default --- guix/scripts/build.scm | 4 +- guix/ui.scm | 101 ++++++++++++++++++++++++++++++++++++-------= ------ 2 files changed, 75 insertions(+), 30 deletions(-) diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index 4dd4fbccd..f6924874d 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -733,9 +733,7 @@ needed." ;; Set the build options before we do anything else. (set-build-options-from-command-line store opts) =20 - (parameterize ((current-build-output-port (if quiet? - (%make-void-port "= w") - (current-error-por= t)))) + (parameterize ((current-build-output-port colorful-build-output-= port)) (let* ((mode (assoc-ref opts 'build-mode)) (drv (options->derivations store opts)) (urls (map (cut string-append <> "/log") diff --git a/guix/ui.scm b/guix/ui.scm index 80f1a4d77..5ddc7c959 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -109,7 +109,7 @@ warning info guix-main - colorize-string)) + colorful-build-output-port)) =20 ;;; Commentary: ;;; @@ -201,8 +201,8 @@ information, or #f if it could not be found." "Load the user provided Scheme source code FILE." (define (error-string frame args) (call-with-output-string - (lambda (port) - (apply display-error frame port (cdr args))))) + (lambda (port) + (apply display-error frame port (cdr args))))) =20 (define tag (make-prompt-tag "user-code")) @@ -490,17 +490,17 @@ FILE." (augmented-system-error-handler file))))) =20 (set! symlink - ;; We 'set!' the global binding because (gnu build ...) modules and si= milar - ;; typically don't use (guix ui). - (error-reporting-wrapper symlink (source target) target)) + ;; We 'set!' the global binding because (gnu build ...) modules an= d similar + ;; typically don't use (guix ui). + (error-reporting-wrapper symlink (source target) target)) =20 (set! copy-file - ;; Note: here we use 'set!', not #:replace, because UIs typically use - ;; 'copy-recursively', which doesn't use (guix ui). - (error-reporting-wrapper copy-file (source target) target)) + ;; Note: here we use 'set!', not #:replace, because UIs typically = use + ;; 'copy-recursively', which doesn't use (guix ui). + (error-reporting-wrapper copy-file (source target) target)) =20 (set! canonicalize-path - (error-reporting-wrapper canonicalize-path (file) file)) + (error-reporting-wrapper canonicalize-path (file) file)) =20 =20 (define (make-regexp* regexp . flags) @@ -898,10 +898,10 @@ replacement if PORT is not Unicode-capable." (catch 'encoding-error (lambda () (call-with-output-string - (lambda (port) - (set-port-encoding! port encoding) - (set-port-conversion-strategy! port 'error) - (display arrow port)))) + (lambda (port) + (set-port-encoding! port encoding) + (set-port-conversion-strategy! port 'error) + (display arrow port)))) (lambda (key . args) "->")))) =20 @@ -1086,7 +1086,7 @@ converted to a space; sequences of more than one li= ne break are preserved." ;; 'texi-fragment->stexi' uses a string port so make sure it's a ;; Unicode-capable one (see .) (with-fluids ((%default-port-encoding "UTF-8")) - (stexi->plain-text (texi-fragment->stexi str)))) + (stexi->plain-text (texi-fragment->stexi str)))) =20 (define (package-field-string package field-accessor) "Return a plain-text representation of PACKAGE field." @@ -1338,10 +1338,10 @@ DURATION-RELATION with the current time." ;; Return TIME at midnight by setting nanoseconds, seconds, minute= s, and ;; hours to zeros. (let ((d (time-utc->date time))) - (date->time-utc - (make-date 0 0 0 0 - (date-day d) (date-month d) - (date-year d) (date-zone-offset d))))) + (date->time-utc + (make-date 0 0 0 0 + (date-day d) (date-month d) + (date-year d) (date-zone-offset d))))) =20 (define generation-ctime-alist (map (lambda (number) @@ -1532,14 +1532,14 @@ found." (parameterize ((program-name command)) ;; Disable canonicalization so we don't don't stat unreasonably. (with-fluids ((%file-port-name-canonicalization #f)) - (dynamic-wind - (const #f) - (lambda () - (apply command-main args)) - (lambda () - ;; Abuse 'exit-hook' (which is normally meant to be used by = the - ;; REPL) to run things like profiling hooks upon completion.= - (run-hook exit-hook))))))) + (dynamic-wind + (const #f) + (lambda () + (apply command-main args)) + (lambda () + ;; Abuse 'exit-hook' (which is normally meant to = be used by the + ;; REPL) to run things like profiling hooks upon = completion. + (run-hook exit-hook))))))) =20 (define (run-guix . args) "Run the 'guix' command defined by command line ARGS. @@ -1631,4 +1631,51 @@ be reset such that subsequent output will not have= any colors in effect." str (color 'RESET))) =20 +(define (handle-string str) + "Accepts input string(str) as argument and checks whether it matches w= ith one=20 +of the regular expressions specified. Upon matching, each substring is c= olorized=20 +with corresponding colors and the modified colored string is returned. I= f the=20 +input string fails match with the following conditionals it returns back= the=20 +unmodified input string." + =20 + (let ((message (or (and=3D> (string-match "^(starting phase )(.*)" st= r) + (lambda (m) + (string-append + (colorize-string (match:substring m 1) '= BLUE) + (colorize-string (match:substring m 2) '= GREEN)))) + + (and=3D> (string-match "^(phase)(.*)(succeeded aft= er)(.*)(seconds)" str) + (lambda (m) + (string-append + (colorize-string (match:substring m 1) '= BLUE) + (colorize-string (match:substring m 2) '= GREEN) + (colorize-string (match:substring m 3) '= BLUE) + (colorize-string (match:substring m 4) '= GREEN) + (colorize-string (match:substring m 5) '= BLUE)))) + + (and=3D> (string-match "^(phase)(.*)(failed after)= (.*)(seconds)" str) + (lambda (m) + (string-append + (colorize-string (match:substring m 1) '= RED) + (colorize-string (match:substring m 2) '= GREEN) + (colorize-string (match:substring m 3) '= RED) + (colorize-string (match:substring m 4) '= GREEN) + (colorize-string (match:substring m 5) '= RED)))) + + ;; Didn=E2=80=99t match with any expression, retur= ns back unmodified string. + str))) + (display message (current-error-port)))) + +(define colorful-build-output-port + (make-soft-port + (vector + (lambda (c) (write c (current-error-port)))=20 + ;; procedure accepting one character for output=20 + handle-string=20 + ;; procedure accepting a string for handle-string procedure + (lambda () (display " " (current-error-port))) + (lambda () (char-upcase (read-char))) + (lambda () (display "@" (current-error-port)))) + "rw")) + ;;; ui.scm ends here --=20 2.11.0 --------------F37A24FBB3C4871FCB04B3D6--