Re: Fwd: Re: Patch file for colorize module

2018-06-15 Thread Sahitihi
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
>>> “make-soft-port” 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 “make-soft-port” again, I recommend
> adding very short comments above each of the procedures in the vector to
> explain what they are intended to do.
>
Please do inform other modifications I have to do and next tasks to
proceed further.

---
Thanks!!
Sahithi.
From 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)
 
-(parameterize ((current-build-output-port (if quiet?
-  (%make-void-port "w")
-  (current-error-port
+   (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))
 
 ;;; 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)
 
   (define tag
 (make-prompt-tag "user-code"))
@@ -490,17 +490,17 @@ FILE."
 (augmented-system-error-handler file)
 
 (set! symlink
-  ;; We 'set!' the global binding because (gnu build ...) modules and similar
-  ;; typically don't use (guix ui).
-  (error-reporting-wrapper symlink (source target) target))
+  ;; We 'set!' the global binding because (gnu build ...) modules and similar
+  ;; typically don't use (guix ui).
+  (error-reporting-wrapper symlink (source target) target))
 
 (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))
 
 (set! canonicalize-path
-  (error-reporting-wrapper canonicalize-path (file) file))
+  (error-reporting-wrapper canonicalize-path (file) file))
 
 
 (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)
 "->"
 
@@ -1086,7 +1086,7 @@ converted to a space; sequences of more than one line 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
 
 (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 

Re: Fwd: Re: Patch file for colorize module

2018-06-13 Thread Ricardo Wurmus


Hi Sahithi,

>> Do you see this too? (If not, can you tell us what terminal you are
>> using?) At the very least you should see that every line starts with a
>> dot.
> I am able to see the colours. I tested with the same hello package
> before sending you the patch. And yes "." for each line.

Good!

>> The next steps are to fix the errors in the regular expressions that
>> swallow certain space characters and to re-read the documentation of
>> “make-soft-port” to make sure that the procedures in the vector behave
>> as they should.
> I will update back once i am through with it.

After reading the documentation for “make-soft-port” again, I recommend
adding very short comments above each of the procedures in the vector to
explain what they are intended to do.

This is generally good practice when working with facilities that don’t
provide named / keyword arguments.

-- 
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-13 Thread Sahithi Yarlagadda
Hi


On Wednesday 13 June 2018 03:42 AM, Ricardo Wurmus wrote:
> Hi Sahithi,
>
> thank you for rebasing it.
>
> I have applied it successfully and I tested the output with this
> command:
>
> ./pre-inst-env guix build --no-grafts --check hello
>
> When I run this in the source directory I do see colours and extra dots
> on every new line, and I see a couple of missing space characters, just
> as your code specifies it.

Yes
> Do you see this too? (If not, can you tell us what terminal you are
> using?) At the very least you should see that every line starts with a
> dot.
I am able to see the colours. I tested with the same hello package
before sending you the patch. And yes "." for each line.
> The next steps are to fix the errors in the regular expressions that
> swallow certain space characters and to re-read the documentation of
> “make-soft-port” to make sure that the procedures in the vector behave
> as they should.
I will update back once i am through with it.
>
> --
> Ricardo
>
>

-- 
Regards
Sahithi




Re: Fwd: Re: Patch file for colorize module

2018-06-12 Thread Ricardo Wurmus


Hi Sahithi,

thank you for rebasing it.

I have applied it successfully and I tested the output with this
command:

./pre-inst-env guix build --no-grafts --check hello

When I run this in the source directory I do see colours and extra dots
on every new line, and I see a couple of missing space characters, just
as your code specifies it.

Do you see this too? (If not, can you tell us what terminal you are
using?) At the very least you should see that every line starts with a
dot.

The next steps are to fix the errors in the regular expressions that
swallow certain space characters and to re-read the documentation of
“make-soft-port” to make sure that the procedures in the vector behave
as they should.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-12 Thread Sahitihi
Hi Ricardo,

> I cannot seem to apply the patch onto either the “wip-sahithi” or
> “master” branches.  Could you rebase your changes on top of the
> “wip-sahithi” branch, please?  If that turns out to be too difficult,
> please rebase the changes on top of the current “master” branch after
> updating your clone of the git repository.

I have rebased the changes on "wip-sahithi" branch and sending the patch
file. I assume i cant rebase to "master" branch as the newly created
branch will have merge conflict with regard to ui.scm which is ahead of
master branch.

---
Thanks!!

Sahithi.
From a7bd2a2b9740d2e5134588d396672afbee33eb6a 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| 41 -
 2 files changed, 41 insertions(+), 4 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)
 
-(parameterize ((current-build-output-port (if quiet?
-  (%make-void-port "w")
-  (current-error-port
+   (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..840ad82e8 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -109,7 +109,7 @@
 warning
 info
 guix-main
-colorize-string))
+colorful-build-output-port))
 
 ;;; Commentary:
 ;;;
@@ -1631,4 +1631,43 @@ be reset such that subsequent output will not have any colors in effect."
str
(color 'RESET)))
 
+(define (handle-string str)
+(let ((message  (or (and=> (string-match "^(starting phase)(.*)" str)
+   (lambda (m)
+ (string-append
+   (colorize-string (match:substring m 1) 'BLUE)
+   (colorize-string (match:substring m 2) 'GREEN
+
+   (and=> (string-match "^(phase) (.*) (succeeded after) (.*) (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=> (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’t match, so return unmodified string.
+   str)))
+(display message (current-error-port
+
+(define colorful-build-output-port
+  (make-soft-port
+   (vector
+(lambda (c) (write c (current-error-port)))
+handle-string
+(lambda () (display "." (current-error-port)))
+(lambda () (char-upcase (read-char)))
+(lambda () (display "@" (current-error-port
+   "rw"))
+
 ;;; ui.scm ends here
-- 
2.11.0



Re: Fwd: Re: Patch file for colorize module

2018-06-12 Thread Ricardo Wurmus


Hi Sahithi,

> When I used "(colorize-string "hello" '(GREEN))" in REPL that gave me a
> error unbound variable colorize-string

This means that “colorize-string” was not defined in the REPL session.
You would need to re-evaluate the definition.

> 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.

This is exactly the cause of the errors.  Let’s look at the definition
of “colorize-string” and “color”:

(define (color . lst) …)
(define (colorize-string str . color-list) …)

Notice the dot?  This is important.  “color” takes any number of
arguments, including zero.  It simply binds all arguments as a list to
“lst”.

When you evaluate “(color 'GREEN 'ON-BLACK 'BOLD)” the value of “lst”
will be equivalent to

(list 'GREEN 'ON-BLACK 'BOLD)

Likewise, when you evaluate “(color)” the value of “lst” will be the
empty list, equivalent to “'()” or “(list)”.

Now, “colorize-string” takes at least one argument “str” followed by any
number of arguments that are bound to “color-list”.

Originally, you did this:

(colorize-string "hello" '(GREEN))

This means that inside “colorize-string” the value of “str” was "hello"
and the value of “color-list” was a list containing a list:

(list '(GREEN))

or

'((GREEN))

This procedure then applies the “color” procedure to the list
“color-list”:

(apply color '((GREEN)))

This is the same as

(color '(GREEN))

And that’s not correct, because “color” expects its arguments to be any
number of symbols, not a list containing symbols.

The “color” procedure tries to find each of its arguments in the
ansi-color-tables, but can’t find '(GREEN) — the table only contains
'GREEN, not '(GREEN).

And that’s why the output is not green.

Your attached code worked fine for me.  I see “Hello!” printed twice in
red.  To make this work for yourself try this:

* open a fresh REPL
* input: ,use (srfi srfi-1)
* paste your file without the module header;
  start with (define ansi-color-tables ….)

You should see the same as I did.

To see what’s going on with your modifications to “(guix ui)” it would
help if you could go through your changes once more (use “git diff” to
be sure to inspect all the lines you have changed) and send your changes
to this list.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-12 Thread Ricardo Wurmus


Hi Sahithi,

> Updated patch is attached.
>
>> Could you send an updated patch?

I cannot seem to apply the patch onto either the “wip-sahithi” or
“master” branches.  Could you rebase your changes on top of the
“wip-sahithi” branch, please?  If that turns out to be too difficult,
please rebase the changes on top of the current “master” branch after
updating your clone of the git repository.

For what it’s worth, when I apply these changes by copying expressions
into the target files manually I see that the port is indeed used.  I
can tell because every new line starts with “.”, which comes from this
line of your soft port:

(lambda () (display "." (current-error-port)))

I also see that the matched lines look … odd.  For example, one of the
matched lines is missing some spaces between words.  Can you figure out
why and correct this in your code?

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-11 Thread Sahitihi
Hi Ricardo,

Text file is attached with all changes I added including colorize module.

The changes added to build.scm is (/(parameterize
((current-build-output-port  colorful-build-output-port)) /)

> Please send me the complete changes as a text file, so that I can apply
> it to my copy of the Guix repository.
>
---
Thanks!!
Sahithi.
(define color-table
  `((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)
  "Return a string containing the ANSI escape sequence for producing the
requested set of attributes in LST.  Unknown attributes are ignored."
  (let ((color-list
 (remove not
 (map (lambda (color) (assq-ref color-table color))
  lst
(if (null? color-list)
""
(string-append
 (string #\esc #\[)
 (string-join color-list ";" 'infix)
 "m"

(define (colorize-string str . color-list)
  "Return a copy of STR colorized using ANSI escape sequences according to the
attributes STR.  At the end of the returned string, the color attributes will
be reset such that subsequent output will not have any colors in effect."
  (string-append
   (apply color color-list)
   str
   (color 'RESET)))

 
(define (handle-string str)
(let ((message  (or (and=> (string-match "^(starting phase)(.*)" str)
   (lambda (m)
 (string-append
   (colorize-string (match:substring m 1) 'BLUE)
   (colorize-string (match:substring m 2) 'GREEN

   (and=> (string-match "^(phase) (.*) (succeeded after) (.*) (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=> (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’t match, so return unmodified string.
   str)))
(display message (current-error-port

(define colorful-build-output-port
  (make-soft-port
   (vector
(lambda (c) (write c (current-error-port)))
handle-string
(lambda () (display "." (current-error-port)))
(lambda () (char-upcase (read-char)))
(lambda () (display "@" (current-error-port
   "rw"))

;;; ui.scm ends here


Re: Fwd: Re: Patch file for colorize module

2018-06-11 Thread Sahitihi
Hi Gábor,

Updated patch is attached.

> Could you send an updated patch?

---
Thanks!!
Sahithi.
>From 765035232a43f09a5c3dbecf77c90499dd1473d4 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda 
Date: Tue, 5 Jun 2018 00:08:32 +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 |  5 +
 guix/ui.scm| 42 +-
 2 files changed, 42 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 guix/scripts/build.scm
 mode change 100644 => 100755 guix/ui.scm

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
old mode 100644
new mode 100755
index 4dd4fbccd..be457443b
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -732,10 +732,7 @@ needed."
   (with-store store
 ;; Set the build options before we do anything else.
 (set-build-options-from-command-line store opts)
-
-(parameterize ((current-build-output-port (if quiet?
-  (%make-void-port "w")
-  (current-error-port
+(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
old mode 100644
new mode 100755
index 80f1a4d77..83302ce30
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -109,7 +109,7 @@
 warning
 info
 guix-main
-colorize-string))
+colorful-build-output-port))
 
 ;;; Commentary:
 ;;;
@@ -1631,4 +1631,44 @@ be reset such that subsequent output will not have any colors in effect."
str
(color 'RESET)))
 
+ 
+(define (handle-string str)
+(let ((message  (or (and=> (string-match "^(starting phase)(.*)" str)
+   (lambda (m)
+ (string-append
+   (colorize-string (match:substring m 1) 'BLUE)
+   (colorize-string (match:substring m 2) 'GREEN
+
+   (and=> (string-match "^(phase) (.*) (succeeded after) (.*) (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=> (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’t match, so return unmodified string.
+   str)))
+(display message (current-error-port
+
+(define colorful-build-output-port
+  (make-soft-port
+   (vector
+(lambda (c) (write c (current-error-port)))
+handle-string
+(lambda () (display "." (current-error-port)))
+(lambda () (char-upcase (read-char)))
+(lambda () (display "@" (current-error-port
+   "rw"))
+
 ;;; ui.scm ends here
-- 
2.11.0



Re: Fwd: Re: Patch file for colorize module

2018-06-11 Thread Ricardo Wurmus


Hi Sahithi,

>> You should see the same as I did.
> This worked for me too.

That’s good.

>> To see what’s going on with your modifications to “(guix ui)” it would
>> help if you could go through your changes once more (use “git diff” to
>> be sure to inspect all the lines you have changed) and send your changes
>> to this list.
>>
> Image is attached. Though I made these changes to ui.scm still I
> couldn't see the reflections in output.

Please send me the complete changes as a text file, so that I can apply
it to my copy of the Guix repository.

-- 
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-11 Thread Gábor Boskovits
2018-06-11 14:14 GMT+02:00 Sahitihi :

> Hi Ricardo,
>
> > You should see the same as I did.
> This worked for me too.
> > To see what’s going on with your modifications to “(guix ui)” it would
> > help if you could go through your changes once more (use “git diff” to
> > be sure to inspect all the lines you have changed) and send your changes
> > to this list.
> >
> Image is attached. Though I made these changes to ui.scm still I
> couldn't see the reflections in output.
>
> ---
> Thanks!!
> Sahithi.
>

Could you send an updated patch?
Thanks,
g_bor


Re: Fwd: Re: Patch file for colorize module

2018-06-11 Thread Sahitihi
Hi Ricardo,

> You should see the same as I did.
This worked for me too.
> To see what’s going on with your modifications to “(guix ui)” it would
> help if you could go through your changes once more (use “git diff” to
> be sure to inspect all the lines you have changed) and send your changes
> to this list.
>
Image is attached. Though I made these changes to ui.scm still I
couldn't see the reflections in output.

---
Thanks!!
Sahithi.


Re: Fwd: Re: Patch file for colorize module

2018-06-09 Thread Sahitihi
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’m sure you can too.  Here’s a hint:
> play around with “(colorize-string "hello" '(GREEN))”.  Does this look
> right?  If not, why is that?  Look closely at the definition of
> “colorize-string”.  What arguments does it expect?  How are arguments
> bound to variables?  How many arguments does “colorize-string” accept?
> Are you really sure about that…?
Attached file contains the details can you please review it once.

---
Thanks!
Sahithi
(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 
 (remove not 
 (map (lambda (color) (assq-ref ansi-color-tables color))
  lst
(if (null? color-list)
""
(string-append 
 (string #\esc #\[)
 (string-join color-list ";" 'infix)
 "m"
  
(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)))



Re: Fwd: Re: Patch file for colorize module

2018-06-08 Thread Ricardo Wurmus


Hi Sahithi,

> As per discussion in irc, I tried using "pk str" and "(pk
> (string-append …))" to show values.
>
> I dint find any differences with and without pk.

That’s expected.  “pk” only peeks at the value — it does not modify it.

The goal of using “pk” was to help you figure out if the values of any
of the inner expressions really are what you want them to be.

> I thought I overlooked, so I tried copying terminal lines to files and
> compared. I couldn't find differences except that of timing.

I found the error already, but I’m sure you can too.  Here’s a hint:
play around with “(colorize-string "hello" '(GREEN))”.  Does this look
right?  If not, why is that?  Look closely at the definition of
“colorize-string”.  What arguments does it expect?  How are arguments
bound to variables?  How many arguments does “colorize-string” accept?
Are you really sure about that…?

Please really do play with this in the REPL and remind yourself of what
you expect to see.  Let’s even ignore color.  What should really happen
to the first argument to “colorize-string” in terms of ANSI codes?

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-08 Thread Sahitihi
Hi Ricardo,

I used this command but even this result with the colorless output.

> You need to use “./pre-inst-env guix” to use your modified version of
> Guix.
>
As per discussion in irc, I tried using "pk str" and  "(pk
(string-append …))" to show values.

I dint find any differences with and without pk.

I thought I overlooked, so I tried copying terminal lines to files and
compared.  I couldn't find differences except that of timing.

Can please help in figuring out where I went wrong.


Thanks!
Sahithi




Re: Fwd: Re: Patch file for colorize module

2018-06-07 Thread Ricardo Wurmus


Hi Sahithi,

> Error disappeared but when i tried to rebuild hello, there were no
> errors at same time no colorful output even.
> I have attached the screen shot.
>
> Can you please check where I went wrong.

Could you tell me the full command you used?

-- 
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-07 Thread Ricardo Wurmus


Hi Sahithi,

> Please find my changes in the patch file attached.

Thanks.  Could you please squash these changes and the previous commit?
This is easier for me to review.

Thanks for fixing the commit message!

>> You have probably noticed that this looks rather repetitive at this
>> point.  Maybe we can think of a better way to express what colours
>> should be applied.  The match group numbers are monotonically
>> increasing, so maybe we can avoid repeated statements of this kind and
>> simply iterate over a list of colours…  I have an idea already; how
>> about you?  :)
>
> I have an idea about making a using filter-string and lists. Not sure
> about functionality but that seems fine. :-P

Could you share some more details?  It doesn’t have to be a ready
implementation in Scheme, but I’d love to hear a few more details.

>> Another thing that’s worth thinking about now is the next step:
>> how can we *optionally* hide all lines between these build system
>> notices about started and completed build phases?
> I din't think of it yet. Will do it in mean process.

That’s okay.  Let’s concentrate on the matter at hand first.

>> One more thing: the fact that handle-string didn’t do the right thing
>> indicates that you didn’t test the changes well enough.  To test them,
>> please locally modify “guix/scripts/build.scm” and/or
>> “guix/scripts/package.scm” to make it use your colourful port instead of
>> the default, as discussed on IRC and in previous emails.
> I made changes to /guix/scripts/build.scm /but that din/t workout. That
> resulted me colourless outputs as before. :-(

That’s because you must have overlooked a comment I made about your code
in “handle-string” :)  Let’s look at it:

>  (define (handle-string str)
> (or (and=> (string-match "^(starting phase)(.*)" str)
[…]
>  ;; Didn’t match, so return unmodified string.
> -  str)
> - (display str target-port))
> +   (display str current-error-port)))

This suffers from the same problem as before.  The result of the
expression starting with “or” is ignored.  You don’t do anything with
it.  After that expression you just run “(display str
current-error-port)”, which prints the original “str” to the (undefined)
“current-error-port”.

You should do something with the result of the previous expression, such
as storing it in a variable.  Then you can use that variable in the
final line.  Something like this:

--8<---cut here---start->8---
(define (handle-string str)
  (let ((message (or (and=> …)
 …
 ;; Nothing matched, use unmodified string.
 str)))
(display message (current-error-port
--8<---cut here---end--->8---

Also note that you must use “(current-error-port)”, not
“current-error-port”.

Could you please send an updated patch?

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-07 Thread Ricardo Wurmus


Sahitihi  writes:

> I used the following commands.
>
>  1. ./pre-inst-env guix build hello
>  2. guix build --check --no-grafts hello
>
>> Could you tell me the full command you used?
>>
> Earlier I got error with first command regarding display. After
> correction to soft port that was fine.
> Second command resulted colorless.

You need to use “./pre-inst-env guix” to use your modified version of
Guix.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-07 Thread Sahitihi
Hi Ricardo,

I used the following commands.

 1.  ./pre-inst-env guix build hello
 2.  guix build --check --no-grafts hello

> Could you tell me the full command you used?
>
Earlier I got error with first command regarding display. After
correction to soft port that was fine.
Second command resulted colorless.
---
Sahithi


Re: Fwd: Re: Patch file for colorize module

2018-06-06 Thread Ricardo Wurmus


Hi Sahithi,

> Patch file is attached with changes.

thanks.

I believe the error you reported on IRC comes from your definition of
“colorful-build-output-port”, which uses “current-error-port” instead of
“(current-error-port)”.  Please correct this and then try again.  I
expect the error to disappear then.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-06 Thread Sahitihi
Hi Ricardo,

Patch file is attached with changes.

I modified guix/scripts/build.scm
   /(parameterize ((current-build-output-port (if quiet?//
// (%make-void-port
"w")//
// 
(current-error-port//
/
to by REPLACING this to use colored output

  /(parameterize ((current-build-output-port 
colorful-build-output-port))/


UI.scm had the necessary changes.


I am getting the following error when building a package

/In ice-9/boot-9.scm://
//    837:9  6 (catch _ _ # ?)//
//    837:9  5 (catch _ _ # ?)//
//In guix/scripts/build.scm://
//   781:24  4 (_)//
//In guix/store.scm://
//   936:15  3 (_ # _ _)//
//   620:13  2 (process-stderr _ _)//
//In unknown file://
//   1 (display "@ build-started /gnu/store/gxv20gis2i4xk8nmn?" ?)//
//   0 (display "@ build-started /gnu/store/gxv20gis2i4xk8nmn?" ?)//
//
//ERROR: In procedure display://
//ERROR: In procedure display: Wrong type argument in position 2:
#«parameter> 870600 proc: #From 3b74ea60a13fef3141f4bedb52f9e8131aaec101 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda 
Date: Tue, 5 Jun 2018 00:08:32 +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 |  5 +
 guix/ui.scm| 42 +-
 2 files changed, 42 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 guix/scripts/build.scm
 mode change 100644 => 100755 guix/ui.scm

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
old mode 100644
new mode 100755
index 4dd4fbccd..be457443b
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -732,10 +732,7 @@ needed."
   (with-store store
 ;; Set the build options before we do anything else.
 (set-build-options-from-command-line store opts)
-
-(parameterize ((current-build-output-port (if quiet?
-  (%make-void-port "w")
-  (current-error-port
+(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
old mode 100644
new mode 100755
index 80f1a4d77..7774cf78c
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -109,7 +109,7 @@
 warning
 info
 guix-main
-colorize-string))
+colorful-build-output-port))
 
 ;;; Commentary:
 ;;;
@@ -1631,4 +1631,44 @@ be reset such that subsequent output will not have any colors in effect."
str
(color 'RESET)))
 
+ 
+(define (handle-string str)
+(let ((message  (or (and=> (string-match "^(starting phase)(.*)" str)
+   (lambda (m)
+ (string-append
+   (colorize-string (match:substring m 1) '(BLUE))
+   (colorize-string (match:substring m 2) '(GREEN)
+
+   (and=> (string-match "^(phase) (.*) (succeeded after) (.*) (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=> (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’t match, so return unmodified string.
+   str)))
+(display message (current-error-port
+
+(define colorful-build-output-port
+  (make-soft-port
+   (vector
+(lambda (c) (write c current-error-port))
+handle-string
+(lambda () (display "." current-error-port))
+(lambda () (char-upcase (read-char)))
+(lambda () (display "@" current-error-port)))
+   "rw"))
+
 ;;; ui.scm ends here
-- 
2.11.0



Re: Fwd: Re: Patch file for colorize module

2018-06-06 Thread Sahitihi
Hi Ricardo,

Please find my changes in the patch file attached.

>   (Generally, you really shouldn’t be developing things as
> “root”.)
>
This time I din't do it as root.
> For this commit a message like this would be appropriate:
Added a appropriate commit message.
> Please always add a so-called docstring for all defined procedures.
Please bear me for this time. I din't add this yet.
> You have probably noticed that this looks rather repetitive at this
> point.  Maybe we can think of a better way to express what colours
> should be applied.  The match group numbers are monotonically
> increasing, so maybe we can avoid repeated statements of this kind and
> simply iterate over a list of colours…  I have an idea already; how
> about you?  :)

I have an idea about making a using filter-string and lists. Not sure
about functionality but that seems fine. :-P
> Another thing that’s worth thinking about now is the next step:
> how can we *optionally* hide all lines between these build system
> notices about started and completed build phases?
I din't think of it yet. Will do it in mean process.
> One more thing: the fact that handle-string didn’t do the right thing
> indicates that you didn’t test the changes well enough.  To test them,
> please locally modify “guix/scripts/build.scm” and/or
> “guix/scripts/package.scm” to make it use your colourful port instead of
> the default, as discussed on IRC and in previous emails.
I made changes to /guix/scripts/build.scm  /but that din/t workout. That
resulted me colourless outputs as before. :-(


Thanks!
Sahithi
From ee2f26b05093cc3227a37b96196ec3a29182 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda 
Date: Thu, 7 Jun 2018 00:07:34 +0530
Subject: [PATCH 2/2] guix: Add coloring soft port.

* guix/ui.scm (handle-string): New procedures.
(colorful-build-output-port): New variable.
---
 guix/ui.scm | 41 -
 1 file changed, 20 insertions(+), 21 deletions(-)
 mode change 100644 => 100755 guix/ui.scm

diff --git a/guix/ui.scm b/guix/ui.scm
old mode 100644
new mode 100755
index 3a36daadc..51a1c4a46
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -109,8 +109,7 @@
 warning
 info
 guix-main
-colorize-string
-guix-colorful-port))
+colorful-build-output-port))
 
 ;;; Commentary:
 ;;;
@@ -1632,43 +1631,43 @@ be reset such that subsequent output will not have any colors in effect."
str
(color 'RESET)))
 
-(define target-port (current-output-port))
  
 (define (handle-string str)
(or (and=> (string-match "^(starting phase)(.*)" str)
(lambda (m)
  (string-append
-   (colorized-display (match:substring m 1) '(BLUE))
-   (colorized-display (match:substring m 2) '(GREEN)
+   (colorize-string (match:substring m 1) '(BLUE))
+   (colorize-string (match:substring m 2) '(GREEN)
 
-   (and=> (string-match "^(phase)(.*) (succeeded)(.*)" str)
+   (and=> (string-match "^(phase) (.*) (succeeded after) (.*) (seconds)" 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)
+  (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=> (string-match "^(phase)(.*) (failed)(.*)" str)
+   (and=> (string-match "^(phase)(.*) (failed after) (.*) (seconds)" 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)
+  (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’t match, so return unmodified string.
-  str)
- (display str target-port))
+   (display str current-error-port)))
 
-(define guix-colorful-port
+(define colorful-build-output-port
   (make-soft-port
(vector
-(lambda (c) (write c target-port))
+(lambda (c) (write c current-error-port))
 handle-string
-(lambda () (display "." target-port))
+(lambda () (display "." current-error-port))
 (lambda () (char-upcase (read-char)))
-(lambda 

Re: Fwd: Re: Patch file for colorize module

2018-06-04 Thread Ludovic Courtès
Hello!

Ricardo Wurmus  skribis:

> I think these are enough hints.  I’d be happy if you could try to
> implement a bit more than a single “if” expression and send us your
> draft implementation within the next few days.  If you have questions
> please feel free to ask for help on #guile or #guix.  I’d like us to
> increase the speed a little, because we seem to be spending too much
> time on introductory work.

I agree.  To make the feedback loop faster, I highly recommend coming to
#guile and #guix on irc.freenode.net (you can use
 as Ricardo mentioned before if you’re not
familiar with IRC.)

For example, if you have questions regarding string-processing functions
in Guile, it’ll be much faster to ask the question on IRC than to wait
for Ricardo to email you.

Thanks in advance,
Ludo’.



Re: Fwd: Re: Patch file for colorize module

2018-06-04 Thread Ricardo Wurmus


Hi Sahithi,

> I used /cond/ conditional and gave a try. This worked out with
> following line.[…]

Good.

Currently, you have always the same code that runs for any match.
Looking at my example you might be able to figure out how to apply a
different colour to different parts of the strings, e.g. using blue for
the name of the build phase and green for the rest.

You will need to use regular expressions with sufficient match groups.

Here’s the example from my email again:

--8<---cut here---start->8---
  (define str  "My name is Al Jarreau and I’m 76 years old.")
  (define expr "(My name is )(.*)( and I’m )(.*)( years old.)")

These are five match groups and we want to modify the second and fourth,
so we can do this:

(or (and=> (string-match expr str)
   (lambda (m)
 (string-append
  (match:substring m 1)
  (string-upcase (match:substring m 2))
  (match:substring m 3)
  (string-reverse (match:substring m 4))
  (match:substring m 5
;; Didn’t match, so return unmodified string.
str)
--8<---cut here---end--->8---

Please make an effort to make the changes in (guix ui) as soon as you
understand how it’s done.

Thanks!

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-04 Thread Sahitihi
Hi Ricardo,

I used /cond/ conditional  and gave a try. This worked out with
following line.

I also included string-match which also worked.

All I need to look for next step is to use regular expressions instead
of string.

> You also see that “if” alone is not sufficient here, because you have
> more than one expression.  You could nest “if” expressions, but that’s
> ugly.  You can use “cond” instead.
   /(cond ((string-match "(starting phase" str) (colorized-display str
'(GREEN))) //
//  ((string-prefix? "succeed" str) (colorized-display str
'(GREEN))) //
//  ((string-prefix? "failed" str) (colorized-display str
'(GREEN))) //
//  (else (display str target-port) )))/

> Please look at the examples in my previous email again.  I used
> “string-match”, “match:substring”, and “and=>”, which you may not be
> familiar with yet.
>

I used them individually but I still dint figure out the way it works in
the example. I will check that as next one.

Thanks!!

Sahithi


Re: Fwd: Re: Patch file for colorize module

2018-06-03 Thread Ricardo Wurmus


Hi Sahithi,

> Hi Ricardo,
>
> I have worked with different possibilities
>> Now all you need to do is work on the “handle-string” procedure.
>>
>> I suggest using simpler matching procedures at first.  To get started
>> try “string-prefix?” and use it with the string “starting phase”.  This
>> won’t work with regular expressions, though.
> String-prefix resulted a boolean output so, I thought of using conditionals.
> Following is the line I added to “handle-string” procedure
>
> /(if (string-prefix? "starting phase" str) (colorized-display str
> '(GREEN)) (display str target-port) ))

Right, this is one way.  But as you have seen,  “string-prefix?” isn’t
all that useful for our purposes.

You also see that “if” alone is not sufficient here, because you have
more than one expression.  You could nest “if” expressions, but that’s
ugly.  You can use “cond” instead.

> Do I need to write multiple definitions for each expression?
>
> '("^starting phase.*"
> "^phase .* succeeded.*"
> "^phase .* failed.*")

That’s up to you.  You could iterate over a list of expressions or you
can explicitly write a case for each expression.

>> If you don’t understand this example please look up the procedures in
>> the Guile manual.
>
> I dint find this example in procedures, may I overlooked somewhere I
> recheck it.

Please look at the examples in my previous email again.  I used
“string-match”, “match:substring”, and “and=>”, which you may not be
familiar with yet.

I think these are enough hints.  I’d be happy if you could try to
implement a bit more than a single “if” expression and send us your
draft implementation within the next few days.  If you have questions
please feel free to ask for help on #guile or #guix.  I’d like us to
increase the speed a little, because we seem to be spending too much
time on introductory work.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-06-03 Thread Sahitihi
Hi Ricardo,

I have worked with different possibilities
> Now all you need to do is work on the “handle-string” procedure.
>
> I suggest using simpler matching procedures at first.  To get started
> try “string-prefix?” and use it with the string “starting phase”.  This
> won’t work with regular expressions, though.
String-prefix resulted a boolean output so, I thought of using conditionals.
Following is the line I added to  “handle-string” procedure

/(if (string-prefix? "starting phase" str) (colorized-display str
'(GREEN)) (display str target-port) ))


/
> While you *can* use “regexp-substitute/global”, I don’t think it’s a
> good fit here, because we may want to extend the string matching
> features, which is difficult to do with “regexp-substitute/global”.
> Instead, try to match regular expressions one by one with “string-match”
> and then operate on the match structure it returns.  If it returns #f
> you can move on to the next expression.  If none match you just return
> the original string.  If one matches you *rebuild* the string, but with
> colours applied.

Do I need to write multiple definitions for each expression?

'("^starting phase.*"
"^phase .* succeeded.*"
"^phase .* failed.*")

> If you don’t understand this example please look up the procedures in
> the Guile manual.

I dint find this example in procedures, may I overlooked somewhere I
recheck it.

Thanks!
Sahithi


Re: Fwd: Re: Patch file for colorize module

2018-06-02 Thread Ricardo Wurmus
Hi Sahithi,

do you have any questions about the next steps outlined in the email
below?

Cheers,
Ricardo


Ricardo Wurmus  writes:

> Hi Sahithi,
>
>>> Have you started on working on this yet?  If so,could you please give us
>>> an update on your progress via email?
>>>
>> I have started out using different functions like
>>
>> |1) regexp-match 2) ||string-contains which resulted same output for
>> strings
>
> The procedures tell you if something matched.
>
>> then i tried 1)
>> string-match 2) string-substitute ended up using string substitute so
>> that the result can be colored one.
>
> “string-match” either returns #f if the expression didn’t match or it
> returns a match structure that tells you *how* the expression was
> matched.  It is especially useful with match groups that are marked with
> parentheses in the regular expression.  See below for an example.
>
>> But I failed executing it. File is
>> attached, Can u suggest where I went wrong.
>
> One obvious failing is in the arguments to “make-soft-port”.  It takes a
> vector of five procedures, but you gave it a vector of one procedure
> followed by an expression beginning with “regexp-substitute/global” and
> then three more procedures.
>
> You need to give it five procedures wrapped in a vector.
>
> How about doing it this way:
>
> --8<---cut here---start->8---
> ;; The port to which we write our potentially colorized strings
> (define target-port (current-output-port))
>
> (define (handle-string str)
>   "Match on the input string STR and return a new string with added
>   color sequences."
>   ;; TODO: match on str and pass the modified string to the output port
>   (display str target-port))
>
> (define my-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"))
>
>  Some tests!
>
> (display "Hello there!" my-colorful-port)  ; no colours
> (display "starting phase “Big gorilla” — watch out!" my-colorful-port)
> (display "phase “Big gorilla” failed" my-colorful-port)
> (display "I heard phase “Big gorilla” failed" my-colorful-port) ; no colours 
> here
> ;;; …and so on…
> --8<---cut here---end--->8---
>
> Now all you need to do is work on the “handle-string” procedure.
>
> I suggest using simpler matching procedures at first.  To get started
> try “string-prefix?” and use it with the string “starting phase”.  This
> won’t work with regular expressions, though.
>
> While you *can* use “regexp-substitute/global”, I don’t think it’s a
> good fit here, because we may want to extend the string matching
> features, which is difficult to do with “regexp-substitute/global”.
> Instead, try to match regular expressions one by one with “string-match”
> and then operate on the match structure it returns.  If it returns #f
> you can move on to the next expression.  If none match you just return
> the original string.  If one matches you *rebuild* the string, but with
> colours applied.
>
> Here’s an example:
>
>   (define str  "My name is Al Jarreau and I’m 76 years old.")
>   (define expr "(My name is )(.*)( and I’m )(.*)( years old.)")
>
> These are five match groups and we want to modify the second and fourth,
> so we can do this:
>
> (or (and=> (string-match expr str)
>(lambda (m)
>  (string-append
>   (match:substring m 1)
>   (string-upcase (match:substring m 2))
>   (match:substring m 3)
>   (string-reverse (match:substring m 4))
>   (match:substring m 5
> ;; Didn’t match, so return unmodified string.
> str)
>
> If you don’t understand this example please look up the procedures in
> the Guile manual.
>
>> As per IRC discussion with Ricardo, I tried installing emacs and
>> running a shell.
>
> That is correct.  We were trying to take a look at the features
> guix-build-log-minor-mode provides, but we didn’t get that far.


--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-05-31 Thread Ricardo Wurmus


Hi Sahithi,

>> Have you started on working on this yet?  If so,could you please give us
>> an update on your progress via email?
>>
> I have started out using different functions like
>
> |1) regexp-match 2) ||string-contains which resulted same output for
> strings

The procedures tell you if something matched.

> then i tried 1)
> string-match 2) string-substitute ended up using string substitute so
> that the result can be colored one.

“string-match” either returns #f if the expression didn’t match or it
returns a match structure that tells you *how* the expression was
matched.  It is especially useful with match groups that are marked with
parentheses in the regular expression.  See below for an example.

> But I failed executing it. File is
> attached, Can u suggest where I went wrong.

One obvious failing is in the arguments to “make-soft-port”.  It takes a
vector of five procedures, but you gave it a vector of one procedure
followed by an expression beginning with “regexp-substitute/global” and
then three more procedures.

You need to give it five procedures wrapped in a vector.

How about doing it this way:

--8<---cut here---start->8---
;; The port to which we write our potentially colorized strings
(define target-port (current-output-port))

(define (handle-string str)
  "Match on the input string STR and return a new string with added
  color sequences."
  ;; TODO: match on str and pass the modified string to the output port
  (display str target-port))

(define my-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"))

 Some tests!

(display "Hello there!" my-colorful-port)  ; no colours
(display "starting phase “Big gorilla” — watch out!" my-colorful-port)
(display "phase “Big gorilla” failed" my-colorful-port)
(display "I heard phase “Big gorilla” failed" my-colorful-port) ; no colours 
here
;;; …and so on…
--8<---cut here---end--->8---

Now all you need to do is work on the “handle-string” procedure.

I suggest using simpler matching procedures at first.  To get started
try “string-prefix?” and use it with the string “starting phase”.  This
won’t work with regular expressions, though.

While you *can* use “regexp-substitute/global”, I don’t think it’s a
good fit here, because we may want to extend the string matching
features, which is difficult to do with “regexp-substitute/global”.
Instead, try to match regular expressions one by one with “string-match”
and then operate on the match structure it returns.  If it returns #f
you can move on to the next expression.  If none match you just return
the original string.  If one matches you *rebuild* the string, but with
colours applied.

Here’s an example:

  (define str  "My name is Al Jarreau and I’m 76 years old.")
  (define expr "(My name is )(.*)( and I’m )(.*)( years old.)")

These are five match groups and we want to modify the second and fourth,
so we can do this:

(or (and=> (string-match expr str)
   (lambda (m)
 (string-append
  (match:substring m 1)
  (string-upcase (match:substring m 2))
  (match:substring m 3)
  (string-reverse (match:substring m 4))
  (match:substring m 5
;; Didn’t match, so return unmodified string.
str)

If you don’t understand this example please look up the procedures in
the Guile manual.

> As per IRC discussion with Ricardo, I tried installing emacs and
> running a shell.

That is correct.  We were trying to take a look at the features
guix-build-log-minor-mode provides, but we didn’t get that far.

--
Ricardo




Re: Fwd: Re: Patch file for colorize module

2018-05-31 Thread Sahitihi
Hi Ricardo,

Sorry for delay. Next time I will make sure to run conversation via
email as well.
> Have you started on working on this yet?  If so,could you please give us
> an update on your progress via email?
>
I have started out using different functions like

|1) regexp-match 2) ||string-contains which resulted same output for strings 
then i tried 1)
string-match 2) string-substitute ended up using string substitute so
that the result can be colored one. But I failed executing it. File is
attached, Can u suggest where I went wrong. As per IRC discussion with
Ricardo, I tried installing emacs and running a shell.  Sahithi|||

(use-modules (ice-9 regex))
(use-modules (ice-9 colorized))
(activate-colorized)

(define p (make-soft-port
   (vector
(lambda (c) (write c stdout))
(regexp-substitute/global #t ("^starting phase.*"
"^phase .* succeeded.*"
"^phase .* failed.*")  "phase"
  'pre (lambda (s) (display (colorized-display s '(GREEN)) stdout))  'post)
(lambda () (display "." stdout))
(lambda () (char-upcase (read-char)))
(lambda () (display "@" stdout)))
   "rw"))
(write s p)