all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Status of Submitted Patches
       [not found]                   ` <87o9hycwl6.fsf@elephly.net>
@ 2018-05-11 21:16                     ` Sahithi Yarlagadda
  2018-05-11 22:21                       ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-05-11 21:16 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Hi


On Wednesday 02 May 2018 01:34 PM, Ricardo Wurmus wrote:
> Hi Sahithi,
>
> I’ve previously sent the message below.  Have you been able to take a
> look at this yet?
>
> --
> Ricardo
>
>>> I have gone through the code under guix/store/ and the outputs are sent
>>> to a specified scheme variable "current-build-output-port"
>> Yes, the “(guix store)” module implements this.
>> “current-build-output-port” is a parameter, which is a dynamically bound
>> variable (i.e. its value can be changed by the caller) and it defaults
>> to the “current-error-port”.
I Understood this.

>> According to the Guile manual
>>
>>    Ports are the way that Guile performs input and output.  Guile can
>>    read in characters or bytes from an “input port”, or write them out
>>    to an “output port”.
>>
>> Ports allow the programmer to ignore the details of input/output sources
>> and sinks and concentrate on shuffling characters or bytes around.  We
>> don’t need to know if the port is connected to a terminal or a file or a
>> network socket.
>>
>> A programmer can implement custom ports with “make-soft-port” and a
>> vector of up to five procedures that provide implementations of certain
>> operations (such as writing a string to the port).  A silly example
>> would be a custom port that reads characters from standard input and
>> turns them to upper-case characters before passing them to whoever reads
>> from the custom port.
(use-modules (ice-9 binary-ports))
(define stdout (current-output-port))
(define stdin (current-input-port))
(display stdin)
(newline)
(display stdout)
(newline)
(write (char-upcase(read-char(current-input-port))))


>> With what you know about terminal escape codes and the port facility
>> that is used in “(guix store)”, can you describe an approach to add
>> colours to some text fragments before they are printed?  There are at
>> least two ways this can be done; one of the two options is more
>> complicated but might result in a clearer and more modular
>> implementation.

For this i tried using

(use-modules (ice-9 binary-ports))
(use-modules (ice-9 colorized)) 
(activate-colorized)
(define stdout (current-output-port))
(define stdin (current-input-port))
(display stdin)
(newline)
(display stdout)
(newline)

(define a (char-upcase(read-char (current-input-port))))
(display a)   
(newline)

(display "\x1b[31ma\x1b[0m")
(newline)

(define b (colorize-string a '(GREEN)))
(display b)


Resulted:

4058: 2 [#<procedure 560e4a6de9c0 at ice-9/boot-9.scm:4051:3 ()>]
In /home/sripathroy/Documents/GNUGuix/experiments/sam.scm:
  17: 1 [#<procedure 560e4ab74920 ()>]
In unknown file:
   ?: 0 [string-append "\x1b[32m" #\S "\x1b[0m"]

ERROR: In procedure string-append:
ERROR: In procedure string-append: Wrong type (expecting string): #\S


I found that the output is stored as #\<char>. How should i convert to
valid format.
>
>

-- 
Regards
Sahithi

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-11 21:16                     ` Status of Submitted Patches Sahithi Yarlagadda
@ 2018-05-11 22:21                       ` Ricardo Wurmus
  2018-05-12  7:50                         ` Ricardo Wurmus
  2018-05-15 17:41                         ` Sahitihi
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-11 22:21 UTC (permalink / raw)
  To: Sahithi Yarlagadda; +Cc: guix-devel


Hi Sahithi,

>>> According to the Guile manual
>>>
>>>    Ports are the way that Guile performs input and output.  Guile can
>>>    read in characters or bytes from an “input port”, or write them out
>>>    to an “output port”.
>>>
>>> Ports allow the programmer to ignore the details of input/output sources
>>> and sinks and concentrate on shuffling characters or bytes around.  We
>>> don’t need to know if the port is connected to a terminal or a file or a
>>> network socket.
>>>
>>> A programmer can implement custom ports with “make-soft-port” and a
>>> vector of up to five procedures that provide implementations of certain
>>> operations (such as writing a string to the port).  A silly example
>>> would be a custom port that reads characters from standard input and
>>> turns them to upper-case characters before passing them to whoever reads
>>> from the custom port.

> (use-modules (ice-9 binary-ports))
> (define stdout (current-output-port))
> (define stdin (current-input-port))
> (display stdin)
> (newline)
> (display stdout)
> (newline)

These definitions have no effect on the code that follows.  “stdout” and
“stdin” have no special meaning.  You are just defining variables with
these names, but you could give them any names.  Giving them names has
no meaningful effect, because you are not using the names later anyway.

> (write (char-upcase(read-char(current-input-port))))

Here you are reading a character from the current input port.  The
result is fed to “char-upcase”, which turns it into an upper-case
variant, and then you write that character to the current default output
port.

While this achieves the goal for a single character it does not
constitute a custom port.  Have you read the documentation for
“make-custom-port” in the Guile manual?

>>> With what you know about terminal escape codes and the port facility
>>> that is used in “(guix store)”, can you describe an approach to add
>>> colours to some text fragments before they are printed?  There are at
>>> least two ways this can be done; one of the two options is more
>>> complicated but might result in a clearer and more modular
>>> implementation.
>
> For this i tried using […]

Actually, I was looking for a description of the two options, not an
implementation :)

Can you think of two possible ways to add colours to text fragments, and
describe them in a few sentences?  If you can only think of one
approach, please describe only that approach.

I guess that you wanted the value of “a” to be printed in colours, but
the code says otherwise.  Here you are just displaying a string that
contains the character “a”, not the value of the variable with the name
“a”.

> (define a (char-upcase(read-char (current-input-port))))
[…]
> (define b (colorize-string a '(GREEN)))
> (display b)
[…]
> 4058: 2 [#<procedure 560e4a6de9c0 at ice-9/boot-9.scm:4051:3 ()>]
> In /home/sripathroy/Documents/GNUGuix/experiments/sam.scm:
>  17: 1 [#<procedure 560e4ab74920 ()>]
> In unknown file:
>  ?: 0 [string-append "\x1b[32m" #\S "\x1b[0m"]
>
> ERROR: In procedure string-append:
> ERROR: In procedure string-append: Wrong type (expecting string): #\S

What type is the value in the variable with name “a”?  “read-char” takes
a port and returns a single character from it, “char-upcase” takes a
character and returns a different character, so “a” holds a character.
As you know, the implementation of “colorize-string” internally glues a
bunch of strings together: a terminal escape sequence to set the colour,
the string to be coloured, and a terminal escape sequence to disable the
colour.  You gave a character to the procedure, but it expects a string.

You can convert strings to characters, but this is not what should be
done here.  If you did that for the string “hello” you would enable
colours, print an “h”, disable colours, enable colours, print an “e”,
disable colours, etc.  That’s rather wasteful because you really want to
only enable colours once, print the string, and then disable colours
again.

But we’re getting ahead of ourselves.  Getting back to the original
problem: can you think of and shortly describe two possible ways to
alter, filter or augment the output that is sent to the
“current-build-output-port” in “(guix store)”?  Try to describe this at
a higher level, ignoring a concrete implementation.  (Bits are for
computers, ideas are for humans.)

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-11 22:21                       ` Ricardo Wurmus
@ 2018-05-12  7:50                         ` Ricardo Wurmus
  2018-05-15 17:41                         ` Sahitihi
  1 sibling, 0 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-12  7:50 UTC (permalink / raw)
  To: Sahithi Yarlagadda; +Cc: guix-devel


Ricardo Wurmus <rekado@elephly.net> writes:

> While this achieves the goal for a single character it does not
> constitute a custom port.  Have you read the documentation for
> “make-custom-port” in the Guile manual?

Correction: I meant “make-soft-port”, not “make-custom-port”.

-- 
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-11 22:21                       ` Ricardo Wurmus
  2018-05-12  7:50                         ` Ricardo Wurmus
@ 2018-05-15 17:41                         ` Sahitihi
  2018-05-20  9:40                           ` Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-15 17:41 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 3143 bytes --]

Hi Ricardo,

> Here you are reading a character from the current input port.  The
> result is fed to “char-upcase”, which turns it into an upper-case
> variant, and then you write that character to the current default output
> port.
>
> While this achieves the goal for a single character it does not
> constitute a custom port.  Have you read the documentation for
> “make-custom-port” in the Guile manual?

I have tried with the following code for, Gábor helped me in process

(use-modules (ice-9 binary-ports))
(use-modules (ice-9 i18n))

(define stdout (current-output-port))
(define s (read(current-input-port)))
(define p (make-soft-port
           (vector
            (lambda (c) (write c stdout))
            (lambda (s) (display (string-upcase! s) stdout))
            (lambda () (display "." stdout))
            (lambda () (char-upcase (read-char)))
            (lambda () (display "@" stdout)))
           "rw"))
(write s p)

The above resulted me with a capitalized output
> What type is the value in the variable with name “a”?  “read-char” takes
> a port and returns a single character from it, “char-upcase” takes a
> character and returns a different character, so “a” holds a character.
> As you know, the implementation of “colorize-string” internally glues a
> bunch of strings together: a terminal escape sequence to set the colour,
> the string to be coloured, and a terminal escape sequence to disable the
> colour.  You gave a character to the procedure, but it expects a string.
>
(use-modules (ice-9 binary-ports)) ;Though name is binary, All ports in
Guile are both binary and textual ports.
(use-modules (ice-9 i18n))  ; The |(ice-9 i18n)| module provides
procedures to manipulate text and other data
(use-modules (ice-9 colorized)) ;Colorizing module
(activate-colorized)

(define stdout (current-output-port)) ;stdout variable act as an output port
(define s (read(current-input-port))) ; s variable reads the input from
input port
;soft ports are used for customization on how output port works
(define p (make-soft-port
           (vector
            (lambda (c) (write c stdout)) ;accepting one character for
output
            (lambda (s) (display (colorized-display (string-upcase! s)
'(GREEN)) stdout)) ;accepting a string, Capitalizing it and then
colorizing with for output
            (lambda () (display "." stdout))
            (lambda () (char-upcase (read-char)))
            (lambda () (display "@" stdout)))
           "rw"))
(write s p)



This results out with a capitalized, colorized output

the description for that goes this way....

The input taken from input port is read and stored in variable "s". 
This variable is passed to make-soft-port.  The variable s is
capitalized by locale conversion then binded with color. the result is
displayed when called.


I have tried the other process using escape codes however failed with
the result i will come with this implementation and procedure in my next
mail


[-- Attachment #2: Type: text/html, Size: 3976 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-15 17:41                         ` Sahitihi
@ 2018-05-20  9:40                           ` Ricardo Wurmus
  2018-05-20 10:47                             ` Gábor Boskovits
  2018-05-23  7:53                             ` Sahitihi
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-20  9:40 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Hi Sahithi,

>> While this achieves the goal for a single character it does not
>> constitute a custom port.  Have you read the documentation for
>> “make-custom-port” in the Guile manual?
>
> I have tried with the following code for, Gábor helped me in process […]

Oh, I haven’t seen those emails on the mailing list.  Please keep the
discussion on the mailing list so that all mentors and the community can
comment.

> the description for that goes this way....
>
> The input taken from input port is read and stored in variable "s".
> This variable is passed to make-soft-port. The variable s is
> capitalized by locale conversion then binded with color. the result is
> displayed when called.

Please try to be a little more precise with the descriptions.  You
defined a new port with “make-soft-port”.  The new port has two
important procedures: one that takes a single character, and another
that takes a string.  In the case of a single character you just pass it
through to the current output port.  In the case of a string, you
colorize it first and then write it to the output port.

The result is a port that will print a coloured string whenever you pass
it a string.

How would you use this in “(guix store)”?  Note that we don’t want to
apply colour to any and all strings there.  We want only certain
messages to be coloured.  Can you please prepare a patch to “(guix
store)” that shows us how you would use this new port?

As a first change, could you please add the relevant parts of “(ice-9
colorized)” to a module in Guix?  We probably don’t want to depend on
having users install this module separately.  We also don’t need all of
it.  Please prepare a patch that adds only the relevant parts to “(guix
ui)” and update the copyright headers.

> I have tried the other process using escape codes however failed with
> the result i will come with this implementation and procedure in my next
> mail

I have not received this email.  Have you worked on this yet?

When you have problems with code please always provide the relevant
parts of your code with the error messages, so that we can help you.

I think that we need to start moving forward at a slighter higher
speed.  Thanks!

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-20  9:40                           ` Ricardo Wurmus
@ 2018-05-20 10:47                             ` Gábor Boskovits
  2018-05-20 13:46                               ` Ricardo Wurmus
  2018-05-23  7:53                             ` Sahitihi
  1 sibling, 1 reply; 68+ messages in thread
From: Gábor Boskovits @ 2018-05-20 10:47 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: Sahitihi, Guix-devel

[-- Attachment #1: Type: text/plain, Size: 2814 bytes --]

2018-05-20 11:40 GMT+02:00 Ricardo Wurmus <rekado@elephly.net>:

>
> Hi Sahithi,
>
> >> While this achieves the goal for a single character it does not
> >> constitute a custom port.  Have you read the documentation for
> >> “make-custom-port” in the Guile manual?
> >
> > I have tried with the following code for, Gábor helped me in process […]
>
> Oh, I haven’t seen those emails on the mailing list.  Please keep the
> discussion on the mailing list so that all mentors and the community can
> comment.
>
>
The discussion was on IRC in a 1:1 conversation. The task Sahitihi wanted
to achieve was to create a soft-port capitalizing all text sent to it. I
helped her
to achieve that. I was thinking about mailing you the details, but it was
only a
few lines of code. I will also make sure to keep you in the circuit in the
future.


> > the description for that goes this way....
> >
> > The input taken from input port is read and stored in variable "s".
> > This variable is passed to make-soft-port. The variable s is
> > capitalized by locale conversion then binded with color. the result is
> > displayed when called.
>
> Please try to be a little more precise with the descriptions.  You
> defined a new port with “make-soft-port”.  The new port has two
> important procedures: one that takes a single character, and another
> that takes a string.  In the case of a single character you just pass it
> through to the current output port.  In the case of a string, you
> colorize it first and then write it to the output port.
>
> The result is a port that will print a coloured string whenever you pass
> it a string.
>
> How would you use this in “(guix store)”?  Note that we don’t want to
> apply colour to any and all strings there.  We want only certain
> messages to be coloured.  Can you please prepare a patch to “(guix
> store)” that shows us how you would use this new port?
>
> As a first change, could you please add the relevant parts of “(ice-9
> colorized)” to a module in Guix?  We probably don’t want to depend on
> having users install this module separately.  We also don’t need all of
> it.  Please prepare a patch that adds only the relevant parts to “(guix
> ui)” and update the copyright headers.
>
> > I have tried the other process using escape codes however failed with
> > the result i will come with this implementation and procedure in my next
> > mail
>
> I have not received this email.  Have you worked on this yet?
>
> When you have problems with code please always provide the relevant
> parts of your code with the error messages, so that we can help you.
>
> I think that we need to start moving forward at a slighter higher
> speed.  Thanks!
>
> --
> Ricardo
>
>
>

[-- Attachment #2: Type: text/html, Size: 3565 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-20 10:47                             ` Gábor Boskovits
@ 2018-05-20 13:46                               ` Ricardo Wurmus
  0 siblings, 0 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-20 13:46 UTC (permalink / raw)
  To: Gábor Boskovits; +Cc: Sahitihi, Guix-devel


Gábor Boskovits <boskovits@gmail.com> writes:

> 2018-05-20 11:40 GMT+02:00 Ricardo Wurmus <rekado@elephly.net>:
>
>>
>> Hi Sahithi,
>>
>> >> While this achieves the goal for a single character it does not
>> >> constitute a custom port.  Have you read the documentation for
>> >> “make-custom-port” in the Guile manual?
>> >
>> > I have tried with the following code for, Gábor helped me in process […]
>>
>> Oh, I haven’t seen those emails on the mailing list.  Please keep the
>> discussion on the mailing list so that all mentors and the community can
>> comment.
>>
>>
> The discussion was on IRC in a 1:1 conversation. The task Sahitihi wanted
> to achieve was to create a soft-port capitalizing all text sent to it. I
> helped her
> to achieve that. I was thinking about mailing you the details, but it was
> only a
> few lines of code. I will also make sure to keep you in the circuit in the
> future.

Ah, okay.  No worries.  I wasn’t on IRC most of last week because I was
travelling.

So one way of doing this is to use a soft port and use it as the current
output port (using parameterize) when colorization is enabled; another
way is to do this where the code is supposed to be displayed.  In the
first method the decision to colorize what and how is done by the port
procedures; in the second approach it’s done right before the string is
passed to “format” or “display”.

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-20  9:40                           ` Ricardo Wurmus
  2018-05-20 10:47                             ` Gábor Boskovits
@ 2018-05-23  7:53                             ` Sahitihi
  2018-05-23  8:21                               ` Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-23  7:53 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]


Hi Ricardo,
> As a first change, could you please add the relevant parts of “(ice-9
> colorized)” to a module in Guix?  We probably don’t want to depend on
> having users install this module separately.  We also don’t need all of
> it.  Please prepare a patch that adds only the relevant parts to “(guix
> ui)” and update the copyright headers.

I think small changes to the attached file will serve the purpose.
But when I tried executing the file, that resulted with a error unbound variable : colorize string 

I am not sure where I went wrong, can you please explain.

--Sahithi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: escape.scm --]
[-- Type: text/x-scheme; name="escape.scm", Size: 1854 bytes --]

(display (colorize-string "Hello!\n" 'RED 'BOLD 'ON-BLUE))

(for-each display
          (list (color 'RED 'BOLD 'ON-BLUE)
                "Hello!"
                 (color 'RESET)))
(define-module (term ansi-color)
     #:export  (color
                colorize-string)
     #:use-module (srfi srfi-1)   ; for 'remove'
     #:use-module (srfi srfi-13)) ; for 'string-join' 

(define ansi-color-tables
  (let ((table (make-hash-table 23)))
    (hashq-set! table 'CLEAR "0")
    (hashq-set! table 'RESET "0")
    (hashq-set! table 'BOLD  "1")
    (hashq-set! table 'DARK  "2")
    (hashq-set! table 'UNDERLINE "4")
    (hashq-set! table 'UNDERSCORE "4")
    (hashq-set! table 'BLINK "5")
    (hashq-set! table 'REVERSE "6")
    (hashq-set! table 'CONCEALED "8")
    (hashq-set! table 'BLACK "30")
    (hashq-set! table 'RED "31")
    (hashq-set! table 'GREEN "32")
    (hashq-set! table 'YELLOW "33")
    (hashq-set! table 'BLUE "34")
    (hashq-set! table 'MAGENTA "35")
    (hashq-set! table 'CYAN "36")
    (hashq-set! table 'WHITE "37")
    (hashq-set! table 'ON-BLACK "40")
    (hashq-set! table 'ON-RED "41")
    (hashq-set! table 'ON-GREEN "42")
    (hashq-set! table 'ON-YELLOW "43")
    (hashq-set! table 'ON-BLUE "44")
    (hashq-set! table 'ON-MAGENTA "45")
    (hashq-set! table 'ON-CYAN "46")
    (hashq-set! table 'ON-WHITE "47")
    table))

(define (color . lst)
  (let ((color-list 
         (remove not 
                 (map (lambda (color) (hashq-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)
  (string-append
   (apply color color-list)
   str
   (color 'RESET)))


^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-23  7:53                             ` Sahitihi
@ 2018-05-23  8:21                               ` Ricardo Wurmus
  2018-05-24 17:16                                 ` Sahitihi
  2018-05-25  3:43                                 ` Sahitihi
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-23  8:21 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Hi Sahithi,

>> As a first change, could you please add the relevant parts of “(ice-9
>> colorized)” to a module in Guix?  We probably don’t want to depend on
>> having users install this module separately.  We also don’t need all of
>> it.  Please prepare a patch that adds only the relevant parts to “(guix
>> ui)” and update the copyright headers.
>
> I think small changes to the attached file will serve the purpose.
> But when I tried executing the file, that resulted with a error unbound variable : colorize string
>
> I am not sure where I went wrong, can you please explain.

Procedures need to be defined before they are used.  On the first line

    (display (colorize-string "Hello!\n" 'RED 'BOLD 'ON-BLUE))

you’re refering to “colorize-string”, which is only defined at the very
bottom.

Another problem is that you’re defining a module, but you aren’t using
it correctly.  A module has a name — in this case that’s “(term
ansi-color)” – and that name must match the path of the file containing
it.  So for “(term ansi-color)” we’d expect the module to be in a file
“term/ansi-color.scm” in a directory in which Guile looks for modules.

For your change to Guix itself I’d suggest adding the needed definitions
to the existing module “(guix ui)”.

Another note about style: I think it would be better to use
“alist->hash-table” instead of “make-hash-table” followed by repeated
modifications to the hash table with “hashq-set!”.  We prefer to avoid
mutation of values when possible.

Regarding copyright headers: please make sure to also add a copyright
line for yourself and a copyright line from the file of guile-colorize
to “(guix ui)”.

When you’re done with these changes, please make a local commit and send
the output of “git format-patch -1”.

Thanks!

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-23  8:21                               ` Ricardo Wurmus
@ 2018-05-24 17:16                                 ` Sahitihi
  2018-05-24 20:00                                   ` Ricardo Wurmus
  2018-05-25  3:43                                 ` Sahitihi
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-24 17:16 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 716 bytes --]

Hi Ricardo,
> Another note about style: I think it would be better to use
> “alist->hash-table” instead of “make-hash-table” followed by repeated
> modifications to the hash table with “hashq-set!”.  We prefer to avoid
> mutation of values when possible.

I have made all necessary modifications. Can please review it once.
> Regarding copyright headers: please make sure to also add a copyright
> line for yourself and a copyright line from the file of guile-colorize
> to “(guix ui)”.
>
> When you’re done with these changes, please make a local commit and send
> the output of “git format-patch -1”.


I will proceed further once it is reviewed. :)

Thanks!!
---
Sahithi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: term ansi-color.scm --]
[-- Type: text/x-scheme; name="term ansi-color.scm", Size: 1552 bytes --]

(define-module (term ansi-color)
     #:export  (color
                colorize-string)
     #:use-module (srfi srfi-1)   ; for 'remove'
     #:use-module (srfi srfi-13)) ; for 'string-join' 

(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)
  (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)
  (string-append
   (apply color color-list)
   str
   (color 'RESET)))

(display (colorize-string "Hello!\n" 'RED 'BOLD 'ON-BLUE))

(for-each display
          (list (color 'RED 'BOLD 'ON-BLUE)
                "Hello!"
                 (color 'RESET)))


^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-24 17:16                                 ` Sahitihi
@ 2018-05-24 20:00                                   ` Ricardo Wurmus
  0 siblings, 0 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-24 20:00 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


Hi Sahithi,

>> Another note about style: I think it would be better to use
>> “alist->hash-table” instead of “make-hash-table” followed by repeated
>> modifications to the hash table with “hashq-set!”.  We prefer to avoid
>> mutation of values when possible.
>
> I have made all necessary modifications. Can please review it once.

Thanks, this looks fine.
You don’t need (srfi srfi-13) for “string-join”.

>> Regarding copyright headers: please make sure to also add a copyright
>> line for yourself and a copyright line from the file of guile-colorize
>> to “(guix ui)”.
>>
>> When you’re done with these changes, please make a local commit and send
>> the output of “git format-patch -1”.
>
>
> I will proceed further once it is reviewed. :)

Please proceed with the patch.  I’d like us to make progress a little
more quickly going forward.

Thanks!

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-23  8:21                               ` Ricardo Wurmus
  2018-05-24 17:16                                 ` Sahitihi
@ 2018-05-25  3:43                                 ` Sahitihi
  2018-05-25  5:18                                   ` Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-25  3:43 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 352 bytes --]

Hi Ricardo,
Done with changes and local commit
> When you’re done with these changes, please make a local commit and send
> the output of “git format-patch -1”.
the following is the output of  “git format-patch -1”

*/0001-Added-Colorize-module-to-Guix-ui.scm.patch/*

Can you please check and guide to proceed further.

Thanks!

--
Sahithi

[-- Attachment #2: Type: text/html, Size: 723 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Status of Submitted Patches
  2018-05-25  3:43                                 ` Sahitihi
@ 2018-05-25  5:18                                   ` Ricardo Wurmus
  2018-05-25 17:59                                     ` Patch file for colorize module Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-25  5:18 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Hi Sahithi,

>> When you’re done with these changes, please make a local commit and send
>> the output of “git format-patch -1”.
> the following is the output of “git format-patch -1”
>
> */0001-Added-Colorize-module-to-Guix-ui.scm.patch/*
>
> Can you please check and guide to proceed further.

Please attach the file of that same name in an email.

-- 
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Patch file for colorize module
  2018-05-25  5:18                                   ` Ricardo Wurmus
@ 2018-05-25 17:59                                     ` Sahitihi
  2018-05-26  6:06                                       ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-25 17:59 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 199 bytes --]

Hi Ricardo,

Please find the attachment..

> Please attach the file of that same name in an email.
Also add any corrections that i need too and next steps to proceed
further. :)


Thanks!
--
Sahithi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Added-colorize-module-to-ui.scm.patch --]
[-- Type: text/x-patch; name="0001-Added-colorize-module-to-ui.scm.patch", Size: 2389 bytes --]

From 93f3c964250587d6272065d555fa07e9bdd47325 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Fri, 25 May 2018 23:23:57 +0530
Subject: [PATCH] Added colorize module to ui.scm

---
 guix/ui.scm | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 8d351607d..e7c5d2972 100755
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -9,7 +9,9 @@
 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
-;;;
+;;; Copyright © 2013,2014 Free Software Foundation, Inc.
+;;; Copyright © 2016 Sahithi Yarlagadda <sahi@swecha.net>
+;;; 
 ;;; This file is part of GNU Guix.
 ;;;
 ;;; GNU Guix is free software; you can redistribute it and/or modify it
@@ -106,7 +108,9 @@
             guix-warning-port
             warning
             info
-            guix-main))
+            guix-main
+            color
+            colorize-string))
 
 ;;; Commentary:
 ;;;
@@ -1578,4 +1582,49 @@ and signal handling has already been set up."
   (initialize-guix)
   (apply run-guix args))
 
+(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)
+  (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)
+  (string-append
+   (apply color color-list)
+   str
+   (color 'RESET)))
+
 ;;; ui.scm ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-25 17:59                                     ` Patch file for colorize module Sahitihi
@ 2018-05-26  6:06                                       ` Sahitihi
  2018-05-26  9:35                                         ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-26  6:06 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

Sorry,

Please find patch file attached to this mail. Kindly ignore the previous
one.

I have made a small change to Copyrights line to that of previous.
> Hi Ricardo,
>
> Please find the attachment..
>
>> Please attach the file of that same name in an email.
> Also add any corrections that i need too and next steps to proceed
> further. :)

Thanks!
--
Sahithi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Added-Colorize-module-and-Copyrights-line-to-ui.scm.patch --]
[-- Type: text/x-patch; name="0002-Added-Colorize-module-and-Copyrights-line-to-ui.scm.patch", Size: 767 bytes --]

From 2cb775a4a8ea3337c7478145ccafffd1fe435df6 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Sat, 26 May 2018 11:32:25 +0530
Subject: [PATCH 2/2] Added Colorize module and Copyrights line to ui.scm

---
 guix/ui.scm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index e7c5d2972..20fbf761f 100755
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -10,7 +10,7 @@
 ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
 ;;; Copyright © 2013,2014 Free Software Foundation, Inc.
-;;; Copyright © 2016 Sahithi Yarlagadda <sahi@swecha.net>
+;;; Copyright © 2018 Sahithi Yarlagadda <sahi@swecha.net>
 ;;; 
 ;;; This file is part of GNU Guix.
 ;;;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26  6:06                                       ` Sahitihi
@ 2018-05-26  9:35                                         ` Ricardo Wurmus
  2018-05-26 12:06                                           ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-26  9:35 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


Hi Sahithi,

please take a look at the file you sent.  It only contains the copyright
line.

You may need to squash the two recent commits into one and then format
the patch.  Squashing can be done easily with “git rebase -i
$start_commit”.

Could you please send another patch?

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26  9:35                                         ` Ricardo Wurmus
@ 2018-05-26 12:06                                           ` Sahitihi
  2018-05-26 14:16                                             ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-26 12:06 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 169 bytes --]

Hi Ricardo,

Please find the attachment. Hope I made it correct this time. :)


On Saturday 26 May 2018 03:05 PM, Ricardo Wurmus wrote:
> git rebase -i
> $start_commit


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Added-Colorize-module-and-Copyrights-line-to-ui.patch --]
[-- Type: text/x-patch; name="0001-Added-Colorize-module-and-Copyrights-line-to-ui.patch", Size: 2405 bytes --]

From 1bd9eaca576e7d958062197b9931d64c0882484e Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Sat, 26 May 2018 17:34:23 +0530
Subject: [PATCH] Added Colorize module and Copyrights line to ui

---
 guix/ui.scm | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 8d351607d..20fbf761f 100755
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -9,7 +9,9 @@
 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
-;;;
+;;; Copyright © 2013,2014 Free Software Foundation, Inc.
+;;; Copyright © 2018 Sahithi Yarlagadda <sahi@swecha.net>
+;;; 
 ;;; This file is part of GNU Guix.
 ;;;
 ;;; GNU Guix is free software; you can redistribute it and/or modify it
@@ -106,7 +108,9 @@
             guix-warning-port
             warning
             info
-            guix-main))
+            guix-main
+            color
+            colorize-string))
 
 ;;; Commentary:
 ;;;
@@ -1578,4 +1582,49 @@ and signal handling has already been set up."
   (initialize-guix)
   (apply run-guix args))
 
+(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)
+  (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)
+  (string-append
+   (apply color color-list)
+   str
+   (color 'RESET)))
+
 ;;; ui.scm ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26 12:06                                           ` Sahitihi
@ 2018-05-26 14:16                                             ` Ricardo Wurmus
  2018-05-26 18:22                                               ` Sahitihi
  2018-05-31  6:26                                               ` Fwd: " Ricardo Wurmus
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-26 14:16 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Hi Sahithi,

> Please find the attachment. Hope I made it correct this time. :)

Thanks, this looks a lot better.  Some comments below:

> From 1bd9eaca576e7d958062197b9931d64c0882484e Mon Sep 17 00:00:00 2001
> From: root <root@localhost.localdomain>

This indicates that you’re doing development as the root user.  It’s
better to use a regular user and only switch to the root user when
absolutely needed.  For work on Guix you will not need to do anything as
the root user.

Also, you can tell git to use your name and email address by running
these commands:

    git config --global user.name "Sahithi Yarlagadda"
    git config --global user.email "sahi@swecha.net"

Any commits you make after that will be properly attributed to you.

> Date: Sat, 26 May 2018 17:34:23 +0530
> Subject: [PATCH] Added Colorize module and Copyrights line to ui

As you can see in the git history of the repository we use a peculiar
convention for describing the changes.  For this patch it would be
something like this:

--8<---------------cut here---------------start------------->8---
ui: Add support for colorization.

* guix/ui.scm (ansi-color-tables): New variable.
(color, colorize-string): New procedures.
--8<---------------cut here---------------end--------------->8---

> diff --git a/guix/ui.scm b/guix/ui.scm
> index 8d351607d..20fbf761f 100755
> --- a/guix/ui.scm
> +++ b/guix/ui.scm
> @@ -9,7 +9,9 @@
>  ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
>  ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
>  ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
> -;;;
> +;;; Copyright © 2013,2014 Free Software Foundation, Inc.

Please add a space after the comma.

> @@ -106,7 +108,9 @@
>              guix-warning-port
>              warning
>              info
> -            guix-main))
> +            guix-main
> +            color
> +            colorize-string))

Do we really need to export the “color” procedure or is it enough to
export “colorize-string”?  Do we even need to export “colorize-string”
at all or should we only export the soft port that applies colours to
some strings?

> @@ -1578,4 +1582,49 @@ and signal handling has already been set up."
>    (initialize-guix)
>    (apply run-guix args))
>
> +(define ansi-color-tables

I think that “ansi-color-tables” could be renamed to “color-table”.

> +(define (color . lst)

For every procedure we need to have a short docstring that describes the
desired behaviour in a complete sentence or two.  Could you provide a
short description of the “color” procedure?  What does it do to its
variable argument list “LST”?

> +(define (colorize-string str . color-list)

The same applies here.

I’d be happy if you could make these changes quickly and send an updated
patch.  Once I receive it I’ll push it to a branch “wip-sahithi” in the
repository.

Thanks in advance!

- - - - - - -

We’re still lacking code to actually use “colorize-string” anywhere.
Could you please prepare a patch or a series of patches that achieves
the following:

* add a soft port to (guix ui) that colorizes strings that match an
  internal list of regular expressions.  The initial list of regular
  expressions could be something like this:

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

  See the documentation for “string-match” for details.

  Initially, the port should print any matching string as just green.
  All other strings should not be modified at all.  This will become a
  little fancier in the future to allow use to apply different colours
  or formatting to different parts of the strings just like it is done
  by “guix-build-log-minor-mode” of the Emacs interface for Guix.  (If
  you haven’t played with that interface yet, please do so.)

* change “guix-package” in “guix/scripts/package.scm” such that it will
  use the new soft port.  Note that “current-build-output-port” in (guix
  store) is a so-called parameter, which can be modified dynamically
  using “parameterize”.  Take a look at “guix/scripts/build.scm” where
  “current-build-output-port” is parameterized to the void port when
  “--quiet” was passed (this causes “guix build” to print no build log).
  The change to “guix-package” should be very similar.

Does this sound like a good idea to you?

By using a soft port I think we can limit future work (e.g. hiding of
parts of the build output) to just the inner procedures and data
structures of the soft port.

Please try to give us short updates every two days or so; this way we
can ensure that any questions you may have can be addressed quickly.
Please also ask right away when anything is unclear or if the suggested
approach seems weird.

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26 14:16                                             ` Ricardo Wurmus
@ 2018-05-26 18:22                                               ` Sahitihi
  2018-05-26 18:38                                                 ` Sahitihi
  2018-05-31  6:26                                               ` Fwd: " Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-26 18:22 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

Hi Ricardo,

> I’d be happy if you could make these changes quickly and send an updated
> patch.  Once I receive it I’ll push it to a branch “wip-sahithi” in the
> repository.
>
I have made the above changes. Please notify if i have to make further
changes.

I mean while, I will be trying out using soft-ports.

Thanks

----
Sahithi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ui-Add-support-for-colorization.patch --]
[-- Type: text/x-patch; name="0001-ui-Add-support-for-colorization.patch", Size: 2197 bytes --]

From 64691615468bbb3e4b9e4bb2322a48c4b6a25d6d Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
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 <mthl@gnu.org>
 ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
-;;; Copyright © 2013,2014 Free Software Foundation, Inc.
+;;; Copyright © 2013, 2014 Free Software Foundation, Inc.
 ;;; Copyright © 2018 Sahithi Yarlagadda <sahi@swecha.net>
 ;;; 
 ;;; 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


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26 18:22                                               ` Sahitihi
@ 2018-05-26 18:38                                                 ` Sahitihi
  2018-05-26 21:20                                                   ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-26 18:38 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 430 bytes --]

I went wrong in squashing. Please check the current attachment.

> Hi Ricardo,
>
>> I’d be happy if you could make these changes quickly and send an updated
>> patch.  Once I receive it I’ll push it to a branch “wip-sahithi” in the
>> repository.
>>
> I have made the above changes. Please notify if i have to make further
> changes.
>
> I mean while, I will be trying out using soft-ports.
>
> Thanks
>
> ----
> Sahithi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ui-Add-support-for-colorization.patch --]
[-- Type: text/x-patch; name="0001-ui-Add-support-for-colorization.patch", Size: 2836 bytes --]

From f3411809f4c9d8e07abf76c08f65e9384405f7d7 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Sat, 26 May 2018 17:34:23 +0530
Subject: [PATCH] ui: Add support for colorization.

* guix/ui.scm (ansi-color-tables): New variable.
(color, colorize-string): New procedures.
---
 guix/ui.scm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 8d351607d..efbcbc88b 100755
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -9,7 +9,9 @@
 ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2016 Roel Janssen <roel@gnu.org>
 ;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
-;;;
+;;; Copyright © 2013, 2014 Free Software Foundation, Inc.
+;;; Copyright © 2018 Sahithi Yarlagadda <sahi@swecha.net>
+;;; 
 ;;; This file is part of GNU Guix.
 ;;;
 ;;; GNU Guix is free software; you can redistribute it and/or modify it
@@ -106,7 +108,8 @@
             guix-warning-port
             warning
             info
-            guix-main))
+            guix-main
+            colorize-string))
 
 ;;; Commentary:
 ;;;
@@ -1578,4 +1581,55 @@ and signal handling has already been set up."
   (initialize-guix)
   (apply run-guix args))
 
+(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)
+    "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 color-table color))
+                      lst))))
+    (if (null? color-list)
+        ""
+        (string-append 
+         (string #\esc #\[)
+         (string-join color-list ";" 'infix)
+         "m"))))
+  
+(define (colorize-string str . color-list)
+  (string-append
+   (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


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26 18:38                                                 ` Sahitihi
@ 2018-05-26 21:20                                                   ` Ricardo Wurmus
  2018-05-27 15:49                                                     ` Gábor Boskovits
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-26 21:20 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


Hi Sahithi,

> I went wrong in squashing. Please check the current attachment.

Thank you.

I’ve made a couple of minor changes and pushed it to the branch
“wip-sahithi”.  These are some of the changes:

* Removed whitespace changes and trailing whitespace.
* Moved the docstring of “colorize-string” to the correct position.
* Changed the author of the commit from “root” to you.

You can run “git fetch origin” and then base your next work on
“origin/wip-sahithi”.

If you have any questions about the next steps please feel free to ask
us.

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Patch file for colorize module
  2018-05-26 21:20                                                   ` Ricardo Wurmus
@ 2018-05-27 15:49                                                     ` Gábor Boskovits
  0 siblings, 0 replies; 68+ messages in thread
From: Gábor Boskovits @ 2018-05-27 15:49 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: Sahithi, Guix-devel

[-- Attachment #1: Type: text/plain, Size: 836 bytes --]

2018-05-26 23:20 GMT+02:00 Ricardo Wurmus <rekado@elephly.net>:

>
> Hi Sahithi,
>
> > I went wrong in squashing. Please check the current attachment.
>
> Thank you.
>
> I’ve made a couple of minor changes and pushed it to the branch
> “wip-sahithi”.


Nice, so now here is a branch where we can see this work. Thanks!

I am happy that Sahithi is making progress.


> These are some of the changes:
>
> * Removed whitespace changes and trailing whitespace.
> * Moved the docstring of “colorize-string” to the correct position.
> * Changed the author of the commit from “root” to you.
>
> You can run “git fetch origin” and then base your next work on
> “origin/wip-sahithi”.
>
> If you have any questions about the next steps please feel free to ask
> us.
>
> --
> Ricardo
>
>
>

[-- Attachment #2: Type: text/html, Size: 1777 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Fwd: Re: Patch file for colorize module
  2018-05-26 14:16                                             ` Ricardo Wurmus
  2018-05-26 18:22                                               ` Sahitihi
@ 2018-05-31  6:26                                               ` Ricardo Wurmus
  2018-05-31 18:25                                                 ` Sahitihi
  1 sibling, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-31  6:26 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


Hi Sahithi,

a couple of days ago I wrote this:

> We’re still lacking code to actually use “colorize-string” anywhere.
> Could you please prepare a patch or a series of patches that achieves
> the following:
>
> * add a soft port to (guix ui) that colorizes strings that match an
>   internal list of regular expressions.  The initial list of regular
>   expressions could be something like this:
>
>   '("^starting phase.*"
>     "^phase .* succeeded.*"
>     "^phase .* failed.*")
>
>   See the documentation for “string-match” for details.
>
>   Initially, the port should print any matching string as just green.
>   All other strings should not be modified at all.  This will become a
>   little fancier in the future to allow use to apply different colours
>   or formatting to different parts of the strings just like it is done
>   by “guix-build-log-minor-mode” of the Emacs interface for Guix.  (If
>   you haven’t played with that interface yet, please do so.)
>
> * change “guix-package” in “guix/scripts/package.scm” such that it will
>   use the new soft port.  Note that “current-build-output-port” in (guix
>   store) is a so-called parameter, which can be modified dynamically
>   using “parameterize”.  Take a look at “guix/scripts/build.scm” where
>   “current-build-output-port” is parameterized to the void port when
>   “--quiet” was passed (this causes “guix build” to print no build log).
>   The change to “guix-package” should be very similar.
>
> Does this sound like a good idea to you?
>
> By using a soft port I think we can limit future work (e.g. hiding of
> parts of the build output) to just the inner procedures and data
> structures of the soft port.
>
> Please try to give us short updates every two days or so; this way we
> can ensure that any questions you may have can be addressed quickly.
> Please also ask right away when anything is unclear or if the suggested
> approach seems weird.

Have you started on working on this yet?  If so,could you please give us
an update on your progress via email?

-- 
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-05-31  6:26                                               ` Fwd: " Ricardo Wurmus
@ 2018-05-31 18:25                                                 ` Sahitihi
  2018-05-31 19:28                                                   ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-05-31 18:25 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 656 bytes --]

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


[-- Attachment #1.2: Type: text/html, Size: 1139 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: String Match.scm --]
[-- Type: text/x-scheme; name="String Match.scm", Size: 547 bytes --]

(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)


^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-05-31 18:25                                                 ` Sahitihi
@ 2018-05-31 19:28                                                   ` Ricardo Wurmus
  2018-06-02 15:01                                                     ` Ricardo Wurmus
  2018-06-03 14:18                                                     ` Sahitihi
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-05-31 19:28 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-05-31 19:28                                                   ` Ricardo Wurmus
@ 2018-06-02 15:01                                                     ` Ricardo Wurmus
  2018-06-03 14:18                                                     ` Sahitihi
  1 sibling, 0 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-02 15:01 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel

Hi Sahithi,

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

Cheers,
Ricardo


Ricardo Wurmus <rekado@elephly.net> 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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-05-31 19:28                                                   ` Ricardo Wurmus
  2018-06-02 15:01                                                     ` Ricardo Wurmus
@ 2018-06-03 14:18                                                     ` Sahitihi
  2018-06-03 19:30                                                       ` Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-03 14:18 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1493 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2100 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-03 14:18                                                     ` Sahitihi
@ 2018-06-03 19:30                                                       ` Ricardo Wurmus
  2018-06-04  7:48                                                         ` Sahitihi
  2018-06-04 11:41                                                         ` Ludovic Courtès
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-03 19:30 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-03 19:30                                                       ` Ricardo Wurmus
@ 2018-06-04  7:48                                                         ` Sahitihi
  2018-06-04 10:03                                                           ` Ricardo Wurmus
  2018-06-04 11:41                                                         ` Ludovic Courtès
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-04  7:48 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1658 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-04  7:48                                                         ` Sahitihi
@ 2018-06-04 10:03                                                           ` Ricardo Wurmus
  2018-06-04 18:51                                                             ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-04 10:03 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-03 19:30                                                       ` Ricardo Wurmus
  2018-06-04  7:48                                                         ` Sahitihi
@ 2018-06-04 11:41                                                         ` Ludovic Courtès
  1 sibling, 0 replies; 68+ messages in thread
From: Ludovic Courtès @ 2018-06-04 11:41 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: Sahitihi, guix-devel

Hello!

Ricardo Wurmus <rekado@elephly.net> 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
<http://webchat.freenode.net/> 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’.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-04 10:03                                                           ` Ricardo Wurmus
@ 2018-06-04 18:51                                                             ` Sahitihi
  2018-06-05 19:44                                                               ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-04 18:51 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]

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




[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Added-a-soft-port-to-guix-ui-that-colorizes-strings-.patch --]
[-- Type: text/x-patch; name="0001-Added-a-soft-port-to-guix-ui-that-colorizes-strings-.patch", Size: 2355 bytes --]

From ab1d07107b3f701b8bcaed8eab3565dc0968f20c Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Tue, 5 Jun 2018 00:08:32 +0530
Subject: [PATCH] Added a soft port to (guix ui) that colorizes strings that
 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))
 
 ;;; Commentary:
 ;;;
@@ -1631,4 +1632,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)))))
+
+       (and=> (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=> (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’t 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
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-04 18:51                                                             ` Sahitihi
@ 2018-06-05 19:44                                                               ` Ricardo Wurmus
  2018-06-06 19:49                                                                 ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-05 19:44 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 7002 bytes --]


Hi Sahithi,

> I have made necessary changes to ui, patch file is attached. Please
> review changes and additionals to be added.

Thank you.  Please see my inline comments below.

> From ab1d07107b3f701b8bcaed8eab3565dc0968f20c Mon Sep 17 00:00:00 2001
> From: root <root@localhost.localdomain>

Please change the author name and email address to your name and email
address.  I’ve previously sent you instructions on how to do this using
“git config”.  (Generally, you really shouldn’t be developing things as
“root”.)

> Date: Tue, 5 Jun 2018 00:08:32 +0530
> Subject: [PATCH] Added a soft port to (guix ui) that colorizes strings that
>  match Regular Expressions.
>

Please follow the conventions for commit messages.  If you take a look
at previous messages you can learn the style.

For this commit a message like this would be appropriate:

--8<---------------cut here---------------start------------->8---
guix: Add coloring soft port.

* guix/ui.scm (foo, bar): New procedures.
(guix-colorful-port): New variable.
--8<---------------cut here---------------end--------------->8---

It should mention all additions by name.

> 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

We may not need to export “colorize-string” at all.

> +(define target-port (current-output-port))

Please remove this and use “(current-error-port)” instead of
“target-port” below.

> +(define (handle-string str)

Please always add a so-called docstring for all defined procedures.

> +   (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)))))
> +
> +       (and=> (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=> (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’t match, so return unmodified string.
> +      str)

This does not do what you may think it does.  This big “or” expression
returns a string, but you are not using the return value anywhere.  See
the next line:

> + (display str target-port))

No matter what string you built up above, you are simply pushing the
*original* string to “target-port”.  That’s not correct.

> +(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"))
> +

This is okay, but please don’t name it “guix-colorful-port” — everything
here is about Guix anyway ;)  I can’t think of a good name right now,
but “colorful-build-output-port” seems okay.

Please add a docstring to explain what this port is used for.

Let’s go back to the code in “handle-string”.  Let’s first look at the
regular expressions:

> +   (or (and=> (string-match "^(starting phase)(.*)" str)
[…]
> +       (and=> (string-match "^(phase)(.*) (succeeded)(.*)" str)
[…]
> +       (and=> (string-match "^(phase)(.*) (failed)(.*)" str)

The strings come from the “gnu-build-system” (and its derivatives).  They
are produced in “(guix build gnu-build-system)”.

We see there that the format strings look like this:

    "starting phase `~a'~%"
    "phase `~a' ~:[failed~;succeeded~] after ~,1f seconds~%"

So the strings look something like this:

    "starting phase `configure'"
    "phase `install' succeeded after 3.2 seconds"
    "phase `patch-generated-file-shebangs' failed after 3.2 seconds"

Keep this in mind if you want to change the expressions in the future.

I have attached a screenshot of the colours that the Emacs interface
produces here.  Can you update the regular expressions so that they also
match the number of seconds?  Then we can give them a different colour.

> +           (lambda (m)
> +             (string-append
> +               (colorized-display (match:substring m 1) '(BLUE))

I don’t see a definition for “colorized-display”.  In your previous
commit you only added “colorize-string”, which is the right tool for
this job as it returns a new colourful string.

> +       (and=> (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)))))

Let’s use red when a phase failed.

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?  :)

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?

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.

Then use “guix package -i” or “guix build” to build and install a
package.  Also add a broken package definition to ensure that the
“failed” messages become red.  Before the internship you added some R
packages, so I think you are already sufficiently familiar with writing
package definitions.

If you have questions about any of this, please ask the friendly people
on the #guix IRC channel for help.


[-- Attachment #2: 2018-06-05-212956_1920x1080_scrot.png --]
[-- Type: image/png, Size: 266108 bytes --]

[-- Attachment #3: Type: text/plain, Size: 13 bytes --]



--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-05 19:44                                                               ` Ricardo Wurmus
@ 2018-06-06 19:49                                                                 ` Sahitihi
  2018-06-06 20:06                                                                   ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-06 19:49 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 1639 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 2623 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0002-guix-Add-coloring-soft-port.patch", Size: 3657 bytes --]

From ee2ccccf26b05093cc3227a37b96196ec3a29182 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
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 () (display "@" target-port)))
+    (lambda () (display "@" current-error-port)))
    "rw"))
 
 ;;; ui.scm ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-06 19:49                                                                 ` Sahitihi
@ 2018-06-06 20:06                                                                   ` Ricardo Wurmus
  2018-06-06 21:20                                                                     ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-06 20:06 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-06 20:06                                                                   ` Ricardo Wurmus
@ 2018-06-06 21:20                                                                     ` Sahitihi
  2018-06-06 21:28                                                                       ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-06 21:20 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 1396 bytes --]

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 _ _ #<procedure 7f6bc6a0c468 at guix/ui.scm:589?> ?)//
//    837:9  5 (catch _ _ #<procedure 7f6bc6a0c480 at guix/ui.scm:697?> ?)//
//In guix/scripts/build.scm://
//   781:24  4 (_)//
//In guix/store.scm://
//   936:15  3 (_ #<build-daemon 256.97 919e60> _ _)//
//   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: #<procedure 779340 at ice-9/boot-9.scm:1419:15
() | (x)»/

[-- Attachment #1.2: Type: text/html, Size: 2067 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 3618 bytes --]

From 3b74ea60a13fef3141f4bedb52f9e8131aaec101 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
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


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-06 21:20                                                                     ` Sahitihi
@ 2018-06-06 21:28                                                                       ` Ricardo Wurmus
  2018-06-07  3:29                                                                         ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-06 21:28 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-06 21:28                                                                       ` Ricardo Wurmus
@ 2018-06-07  3:29                                                                         ` Sahitihi
  2018-06-07  5:22                                                                           ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-07  3:29 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

Hi Ricardo,

Thanks for the input.

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

-----
Sahithi

[-- Attachment #2: Guix.png --]
[-- Type: image/png, Size: 117320 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-07  3:29                                                                         ` Sahitihi
@ 2018-06-07  5:22                                                                           ` Ricardo Wurmus
  2018-06-07  7:47                                                                             ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-07  5:22 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-07  5:22                                                                           ` Ricardo Wurmus
@ 2018-06-07  7:47                                                                             ` Sahitihi
  2018-06-07  8:25                                                                               ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-07  7:47 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 326 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 709 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-07  7:47                                                                             ` Sahitihi
@ 2018-06-07  8:25                                                                               ` Ricardo Wurmus
  2018-06-08 17:01                                                                                 ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-07  8:25 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Sahitihi <sahi@swecha.net> 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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-07  8:25                                                                               ` Ricardo Wurmus
@ 2018-06-08 17:01                                                                                 ` Sahitihi
  2018-06-09  0:57                                                                                   ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-08 17:01 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-08 17:01                                                                                 ` Sahitihi
@ 2018-06-09  0:57                                                                                   ` Ricardo Wurmus
  2018-06-09 18:08                                                                                     ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-09  0:57 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-09  0:57                                                                                   ` Ricardo Wurmus
@ 2018-06-09 18:08                                                                                     ` Sahitihi
  2018-06-09 20:57                                                                                       ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-09 18:08 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: term ansi-color.scm --]
[-- Type: text/x-scheme; name="term ansi-color.scm", Size: 2655 bytes --]

(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)))


^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-09 18:08                                                                                     ` Sahitihi
@ 2018-06-09 20:57                                                                                       ` Ricardo Wurmus
  2018-06-11 12:14                                                                                         ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-09 20:57 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-09 20:57                                                                                       ` Ricardo Wurmus
@ 2018-06-11 12:14                                                                                         ` Sahitihi
  2018-06-11 12:28                                                                                           ` Gábor Boskovits
  2018-06-11 12:37                                                                                           ` Fwd: Re: Patch file for colorize module Ricardo Wurmus
  0 siblings, 2 replies; 68+ messages in thread
From: Sahitihi @ 2018-06-11 12:14 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]

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.

[-- Attachment #2: Guix.png --]
[-- Type: image/png, Size: 64588 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-11 12:14                                                                                         ` Sahitihi
@ 2018-06-11 12:28                                                                                           ` Gábor Boskovits
  2018-06-11 16:21                                                                                             ` Sahitihi
  2018-06-11 12:37                                                                                           ` Fwd: Re: Patch file for colorize module Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Gábor Boskovits @ 2018-06-11 12:28 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

2018-06-11 14:14 GMT+02:00 Sahitihi <sahi@swecha.net>:

> 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

[-- Attachment #2: Type: text/html, Size: 1142 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-11 12:14                                                                                         ` Sahitihi
  2018-06-11 12:28                                                                                           ` Gábor Boskovits
@ 2018-06-11 12:37                                                                                           ` Ricardo Wurmus
  2018-06-11 16:31                                                                                             ` Sahitihi
  1 sibling, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-11 12:37 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-11 12:28                                                                                           ` Gábor Boskovits
@ 2018-06-11 16:21                                                                                             ` Sahitihi
  2018-06-12 14:12                                                                                               ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-11 16:21 UTC (permalink / raw)
  To: Gábor Boskovits; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 98 bytes --]

Hi Gábor,

Updated patch is attached.

> Could you send an updated patch?

---
Thanks!!
Sahithi.

[-- Attachment #1.2: Type: text/html, Size: 515 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 3503 bytes --]

From 765035232a43f09a5c3dbecf77c90499dd1473d4 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
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


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-11 12:37                                                                                           ` Fwd: Re: Patch file for colorize module Ricardo Wurmus
@ 2018-06-11 16:31                                                                                             ` Sahitihi
  0 siblings, 0 replies; 68+ messages in thread
From: Sahitihi @ 2018-06-11 16:31 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 352 bytes --]

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.

[-- Attachment #1.2: Type: text/html, Size: 695 bytes --]

[-- Attachment #2: Colorize module and Soft port --]
[-- Type: text/plain, Size: 3044 bytes --]

(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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-11 16:21                                                                                             ` Sahitihi
@ 2018-06-12 14:12                                                                                               ` Ricardo Wurmus
  2018-06-12 21:06                                                                                                 ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-12 14:12 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-12 14:12                                                                                               ` Ricardo Wurmus
@ 2018-06-12 21:06                                                                                                 ` Sahitihi
  2018-06-12 22:12                                                                                                   ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-12 21:06 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 3424 bytes --]

From a7bd2a2b9740d2e5134588d396672afbee33eb6a Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
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


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-12 21:06                                                                                                 ` Sahitihi
@ 2018-06-12 22:12                                                                                                   ` Ricardo Wurmus
  2018-06-13 16:08                                                                                                     ` Sahithi Yarlagadda
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-12 22:12 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-12 22:12                                                                                                   ` Ricardo Wurmus
@ 2018-06-13 16:08                                                                                                     ` Sahithi Yarlagadda
  2018-06-13 19:15                                                                                                       ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-13 16:08 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-13 16:08                                                                                                     ` Sahithi Yarlagadda
@ 2018-06-13 19:15                                                                                                       ` Ricardo Wurmus
  2018-06-15 20:16                                                                                                         ` Sahitihi
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-13 19:15 UTC (permalink / raw)
  To: Sahithi Yarlagadda; +Cc: guix-devel


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

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Fwd: Re: Patch file for colorize module
  2018-06-13 19:15                                                                                                       ` Ricardo Wurmus
@ 2018-06-15 20:16                                                                                                         ` Sahitihi
  2018-06-15 21:47                                                                                                           ` Next steps Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-15 20:16 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 846 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 8552 bytes --]

From 2d4a335d0262e59784912b6cd922ae9283f17cb4 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
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 <http://bugs.gnu.org/11197>.)
   (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 midnight by setting nanoseconds, seconds, minutes, 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)))))
 
     (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)))))))
 
 (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)))
 
+(define (handle-string str)
+  "Accepts input string(str) as argument and checks whether it matches with one 
+of the regular expressions specified. Upon matching, each substring is colorized 
+with corresponding colors and the modified colored string is returned. If the 
+input string fails match with the following conditionals it returns back the 
+unmodified input string."
+  
+  (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 with any expression, returns 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))) 
+    ;; procedure accepting one character for output 
+    handle-string 
+    ;; 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
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Next steps
  2018-06-15 20:16                                                                                                         ` Sahitihi
@ 2018-06-15 21:47                                                                                                           ` Ricardo Wurmus
  2018-06-16 14:55                                                                                                             ` Sahitihi
  2018-06-24 18:25                                                                                                             ` Sahithi Yarlagadda
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-15 21:47 UTC (permalink / raw)
  To: Sahithi; +Cc: guix-devel


Hi Sahithi,

> I have fixed the errors mentioned bellow, Please do check and notify me
> for further modifications.

Excellent, this looks better.  Unfortunately, your patch includes a
couple of unrelated indentation changes.  Please remove those.

Let’s talk about the next steps.


1) Enabling colours only *optionally*.

We modified “guix/scripts/build.scm” to test the changes, but this
really should be optional, because not everybody wants colours.

For example, when the environment variable “NO_COLOR” is set to any
value we should not use colours.  Likewise, when the environment
variable “INSIDE_EMACS” has a value (meaning that this is a shell in
Emacs where people should rather use “guix-build-log-minor-mode”) we
should not print colours.  You can read the values of environment
variables with the “getenv” procedure (it is explained in the manual).

This check could be in “guix/scripts/build.scm” and
“guix/scripts/package.scm” to either use “colorful-build-output-port” or
“(current-error-port)”.

Another option is to do this in the definition of
“colorful-build-output-port” itself, which would either be defined with
“handle-string” or “handle-plain-string” (which uses no colours)
dependent on these environment variables.

This option would be better, because we want to extend the soft port to
also filter lines optionally (when “guix package” is used).  Instead of
swapping out the full port we could configure it with various options
like “color?” and “filter?”.

Time estimate: This should take no longer than 3 days.


2) Fixing the other soft port procedures

Currently we have this:

> +   (vector
> +    (lambda (c) (write c (current-error-port)))
> +    ;; procedure accepting one character for output
> +    handle-string
> +    ;; procedure accepting a string for handle-string procedure
> +    (lambda () (display " " (current-error-port)))
> +    (lambda () (char-upcase (read-char)))
> +    (lambda () (display "@" (current-error-port))))

Please move the comments *above* the procedures they describe.  Note
that the third procedure is still wrong – according to the manual it
should force or flush the output, not print a space.  Please use
“(lambda () (force-output (current-error-port)))” instead.

The fourth procedure reads a character.  Currently it also turns the
read character to an uppercase character.  We don’t need that, because
we don’t read from the port at all.  You can use “(const #t)” instead.

Time estimate: This should take less than 10 minutes to fix.


3) Filtering all lines between “starting phase” and “phase
succeeded/failed”.

Currently, the port applies colours and passes all other lines through
unmodified.  When using “guix package” it may be good to *hide* other
lines and replace them with a progress indicator.  The first step to
test this would be to replace *any* other line with “.”.  You would then
only see the lines that announce phases, but not the build output.

(Later we would change the dots for a cute little “spinner” animation.)

Can you think of a way to *only* filter lines when “guix package” is
used but not when “guix build” is used?  Maybe we need another variation
of the port…?

Time estimate: You should have some results and an idea how to finish
this after no more than a day of work.


4) Making the colorization prettier.

We repeat “colorize-string” a lot!  Can we do better?  How about using
“match:count” and a list of colours to be applied in order?

Start playing with something like this in the REPL:

--8<---------------cut here---------------start------------->8---


(use-modules (ice-9 match)   ; need this for “match-lambda”
             (srfi srfi-1))  ; need this for “any”

(define str "phase foo failed after 100 seconds")


;; Each list item in “patterns” is a regular expression followed by a
;; number of colours.
(let ((patterns '(("^(starting phase )(.*)"
                   BLUE GREEN)
                  ("^(phase)(.*)(succeeded after)(.*)(seconds)"
                   GREEN BLUE GREEN BLUE GREEN)
                  ("^(phase)(.*)(failed after)(.*)(seconds)"
                   RED BLUE RED BLUE RED))))

   ;; See if “any” of the patterns matches, i.e. returns a string and
   ;; not just #f.  We use “match-lambda” to bind the pattern to the
   ;; variable “pattern” and the list of colours to the variable
   ;; “colors”.

   (or (any (match-lambda
             ((pattern . colors)
              ;; TODO: use string-match, match:count, match:substring,
              ;; colorize-string, and=>, etc to see if a pattern matches
              ;; and to transform the string according to “colors”.

              ;; If the pattern does not match return #f to
              ;; automatically try the next, thanks to “any”.
              #f
             ))
             patterns)
       ;; Nothing matched, so return the string without changes.
       str))
--8<---------------cut here---------------end--------------->8---

Take your time to understand this one.  Play around with this in the
REPL and ask questions on IRC (both #guile and #guix) if the manual does
not answer your questions.  Once you understand it, it should take no
longer than 3 days to implement this.

All together, these steps should take no longer than two weeks to
implement.  What do you think?

Remember to play in the REPL, use “pk” to confirm that variables have
the values you expect, and to ask others if you get stuck.

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-15 21:47                                                                                                           ` Next steps Ricardo Wurmus
@ 2018-06-16 14:55                                                                                                             ` Sahitihi
  2018-06-21 11:05                                                                                                               ` Ricardo Wurmus
  2018-06-24 18:25                                                                                                             ` Sahithi Yarlagadda
  1 sibling, 1 reply; 68+ messages in thread
From: Sahitihi @ 2018-06-16 14:55 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

Hi Ricardo,

Patch file is attached with the following changes.
> Excellent, this looks better.  Unfortunately, your patch includes a
> couple of unrelated indentation changes.  Please remove those.
>
> 2) Fixing the other soft port procedures

As described I will proceed on with next steps and will make ensure to
complete it in-time.

----
Thanks!!
Sahithi

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 3905 bytes --]

From 99526f5624633e5fdc72fe8fb280b1279bea0636 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
Date: Sat, 16 Jun 2018 13:21:42 +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            | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 4dd4fbccd..81ad255d8 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..88e5fa6b7 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,51 @@ be reset such that subsequent output will not have any colors in effect."
    str
    (color 'RESET)))
 
+(define (handle-string str)
+ "Accepts input string(str) as argument and checks whether it matches with one 
+of the regular expressions specified. Upon matching, each substring is colorized 
+with corresponding colors and the modified colored string is returned. If the 
+input string fails match with the following conditionals it returns back the 
+unmodified input string."
+    (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 with any expression, returns back unmodified string.
+       str)))
+    (display message (current-error-port))))
+
+(define colorful-build-output-port
+  (make-soft-port
+   (vector
+     ;; procedure accepting one character for output
+    (lambda (c) (write c (current-error-port)))
+     ;; procedure accepting a string for handle-string procedure
+    handle-string
+    (lambda () (force-output (current-error-port)))
+    (const #t)
+    (lambda () (display "@" (current-error-port))))
+   "rw"))
+
+
 ;;; ui.scm ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-16 14:55                                                                                                             ` Sahitihi
@ 2018-06-21 11:05                                                                                                               ` Ricardo Wurmus
  2018-06-21 16:54                                                                                                                 ` Sahithi Yarlagadda
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-21 11:05 UTC (permalink / raw)
  To: Sahitihi; +Cc: guix-devel


Hi Sahithi,

> Patch file is attached with the following changes.
>> Excellent, this looks better.  Unfortunately, your patch includes a
>> couple of unrelated indentation changes.  Please remove those.
>>
>> 2) Fixing the other soft port procedures
>
> As described I will proceed on with next steps and will make ensure to
> complete it in-time.

as I previously informed you on IRC I have pushed your last patch to the
“wip-sahithi” branch.

Could you please let us know what the current status of your work is?
I’m on #guix and #guile right now, so if you have time please come by
and we can discuss any problems you might have.

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-21 11:05                                                                                                               ` Ricardo Wurmus
@ 2018-06-21 16:54                                                                                                                 ` Sahithi Yarlagadda
  2018-06-25 20:13                                                                                                                   ` Sahithi Yarlagadda
  0 siblings, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-21 16:54 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Hi Ricardo,

Thank you. I felt merging to wip-sahithi will allow me to work from
different machines and also reset back to the original branch to undo
all changes.
> as I previously informed you on IRC I have pushed your last patch to the
> “wip-sahithi” branch.
I am done with 2nd task out of given 4 tasks and that was included in my
previous patch.
I am currently working on 4th task. I will be back with status once I am
done. I will be asking doubts on #guix and #guile.
I have an basic overview of executing 3rd task.

> Could you please let us know what the current status of your work is?
> I’m on #guix and #guile right now, so if you have time please come by
> and we can discuss any problems you might have.
---
Thanks!!
Sahithi.

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-15 21:47                                                                                                           ` Next steps Ricardo Wurmus
  2018-06-16 14:55                                                                                                             ` Sahitihi
@ 2018-06-24 18:25                                                                                                             ` Sahithi Yarlagadda
  2018-06-24 20:22                                                                                                               ` Ricardo Wurmus
  1 sibling, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-24 18:25 UTC (permalink / raw)
  To: Ricardo Wurmus, help-guix; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 319 bytes --]

Hi all,

The following are the changes that I made earlier.... and changes worked
fine...

This patch is pushed to my branch wip-sahithi

But when I try executing it now I don't find its results.... not even
soft-port is getting called...

May I know the reason behind this....


---
Thanks!!
Sahithi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Add-coloring-soft-port.patch --]
[-- Type: text/x-patch; name="0001-guix-Add-coloring-soft-port.patch", Size: 3905 bytes --]

From 99526f5624633e5fdc72fe8fb280b1279bea0636 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
Date: Sat, 16 Jun 2018 13:21:42 +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            | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 4dd4fbccd..81ad255d8 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..88e5fa6b7 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,51 @@ be reset such that subsequent output will not have any colors in effect."
    str
    (color 'RESET)))
 
+(define (handle-string str)
+ "Accepts input string(str) as argument and checks whether it matches with one 
+of the regular expressions specified. Upon matching, each substring is colorized 
+with corresponding colors and the modified colored string is returned. If the 
+input string fails match with the following conditionals it returns back the 
+unmodified input string."
+    (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 with any expression, returns back unmodified string.
+       str)))
+    (display message (current-error-port))))
+
+(define colorful-build-output-port
+  (make-soft-port
+   (vector
+     ;; procedure accepting one character for output
+    (lambda (c) (write c (current-error-port)))
+     ;; procedure accepting a string for handle-string procedure
+    handle-string
+    (lambda () (force-output (current-error-port)))
+    (const #t)
+    (lambda () (display "@" (current-error-port))))
+   "rw"))
+
+
 ;;; ui.scm ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-24 18:25                                                                                                             ` Sahithi Yarlagadda
@ 2018-06-24 20:22                                                                                                               ` Ricardo Wurmus
  2018-06-24 20:33                                                                                                                 ` Sahithi Yarlagadda
  0 siblings, 1 reply; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-24 20:22 UTC (permalink / raw)
  To: Sahithi Yarlagadda; +Cc: guix-devel, help-guix


Hi Sahithi,

I checked out the “wip-sahithi” branch and ran this command in a
terminal (urxvt):

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

I do see colours for phase start and end notices, so the code is fine.

What terminal are you using?  Did this not work for you before?  What
has changed since?

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-24 20:22                                                                                                               ` Ricardo Wurmus
@ 2018-06-24 20:33                                                                                                                 ` Sahithi Yarlagadda
  0 siblings, 0 replies; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-24 20:33 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel, help-guix

Hi


On Monday 25 June 2018 01:52 AM, Ricardo Wurmus wrote:
> Hi Sahithi,
>
> I checked out the “wip-sahithi” branch and ran this command in a
> terminal (urxvt):
>
>     ./pre-inst-env guix build --check --no-grafts hello
>
> I do see colours for phase start and end notices, so the code is fine.
It worked for me now, when i tested it by checking out to wip-sahithi
branch.
> What terminal are you using?  Did this not work for you before?  What
> has changed since?
Gnome terminal
It worked for me earlier as well, i tested the code by building the
hello package before sending the patch.

Unsure why it dint work, i did couple of changes and reverted back
thought. Seems i missed something out.
>
> --
> Ricardo
>
>

-- 
Regards
Sahithi

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-21 16:54                                                                                                                 ` Sahithi Yarlagadda
@ 2018-06-25 20:13                                                                                                                   ` Sahithi Yarlagadda
  2018-06-25 20:28                                                                                                                     ` Ricardo Wurmus
  0 siblings, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-25 20:13 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 482 bytes --]

Hi Ricardo,

I think I am done with basic changes for 4th task. File is attached. As
mentioned in IRC output is in escape code sequence when I tried in REPL.

> I am done with 2nd task out of given 4 tasks and that was included in my
> previous patch.
> I am currently working on 4th task. 
I am able to filter lines.
I am trying out  to*only* filter lines when “guix package” is used but
not when “guix build” by adding other port.


----
Thanks!!
Sahithi

[-- Attachment #1.2: Type: text/html, Size: 1099 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Try.scm --]
[-- Type: text/x-scheme; name="Try.scm", Size: 1922 bytes --]

(use-modules (ice-9 match)   ; need this for “match-lambda”
             (srfi srfi-1)
              (srfi srfi-26))  ; need this for “any”

(define str "phase foo failed after 100 seconds")


;; Each list item in “patterns” is a regular expression followed by a
;; number of colours.
(let ((patterns '(("^(starting phase )(.*)"
                   BLUE GREEN)
                  ("^(phase)(.*)(succeeded after)(.*)(seconds)"
                   GREEN BLUE GREEN BLUE GREEN)
                  ("^(phase)(.*)(failed after)(.*)(seconds)"
                   RED BLUE RED BLUE RED))))

   ;; See if “any” of the patterns matches, i.e. returns a string and
   ;; not just #f.  We use “match-lambda” to bind the pattern to the
   ;; variable “pattern” and the list of colours to the variable
   ;; “colors”.

   (or (any (match-lambda
             ((pattern . colors)
              ;; TODO: use string-match, match:count, match:substring,
              ;; colorize-string, and=>, etc to see if a pattern matches
              ;; and to transform the string according to “colors”.

              ;; If the pattern does not match return #f to
              ;; automatically try the next, thanks to “any”.
              
              ;;(colorize-string (match:substring (match:count (string-match pattern str))) colors)
           
              (and=> (string-match pattern str)
           (lambda (m)
              ;     (colorize-string (map match:substring m (iota (- (match:count m) 1) 1) colors)))



          ;(map (cut match:substring m <>) (iota (- (match:count m) 1) 1))))

(string-join (map (lambda (n color) (colorize-string (match:substring m n) color))  (iota (- (match:count m) 1) 1) colors))))
         
           
             ))
             patterns)
       ;; Nothing matched, so return the string without changes.
       str))

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-25 20:13                                                                                                                   ` Sahithi Yarlagadda
@ 2018-06-25 20:28                                                                                                                     ` Ricardo Wurmus
  2018-06-26 20:01                                                                                                                       ` Gábor Boskovits
  2018-06-29 22:51                                                                                                                       ` Sahithi Yarlagadda
  0 siblings, 2 replies; 68+ messages in thread
From: Ricardo Wurmus @ 2018-06-25 20:28 UTC (permalink / raw)
  To: Sahithi Yarlagadda; +Cc: guix-devel


Hi Sahithi,

> I think I am done with basic changes for 4th task. File is attached. As
> mentioned in IRC output is in escape code sequence when I tried in REPL.

Great.  Please change ui.scm directly and send a patch that can be
applied to the wip-sahithi branch.

Please also pay attention to these things:

* indent the lines properly (Emacs does the right thing when you hit TAB)
* don’t leave extraneous comments or dead code
* make sure long expressions are broken up

>> I am done with 2nd task out of given 4 tasks and that was included in my
>> previous patch.
>> I am currently working on 4th task.
> I am able to filter lines.
> I am trying out to*only* filter lines when “guix package” is used but
> not when “guix build” by adding other port.

The next step here would be to not print a dot for each line but to
display a spinner instead, i.e. a sequence of characters that look like
a spinning animation.  For each line the animation could be advanced by
one (so it will spin really fast).

Danny previously suggested this implementation:

   https://lists.gnu.org/archive/html/guix-patches/2017-07/msg00068.html

You may be able to take a part of that patch and adapt it.  The key here
is really: keep track of the animation position and use backspace to
delete the previously printed character before displaying the next.

If you don’t like the spinner animation you could also pick one of
these and try implementing them instead:

   https://stackoverflow.com/questions/2685435/cooler-ascii-spinners

Have fun!

--
Ricardo

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-25 20:28                                                                                                                     ` Ricardo Wurmus
@ 2018-06-26 20:01                                                                                                                       ` Gábor Boskovits
  2018-06-29 22:51                                                                                                                       ` Sahithi Yarlagadda
  1 sibling, 0 replies; 68+ messages in thread
From: Gábor Boskovits @ 2018-06-26 20:01 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: Sahitihi, guix-devel

[-- Attachment #1: Type: text/plain, Size: 1806 bytes --]

Ricardo Wurmus <rekado@elephly.net> ezt írta (időpont: 2018. jún. 25., H
22:29):

>
> Hi Sahithi,
>
> > I think I am done with basic changes for 4th task. File is attached. As
> > mentioned in IRC output is in escape code sequence when I tried in REPL.
>
> Great.  Please change ui.scm directly and send a patch that can be
> applied to the wip-sahithi branch.
>


Hello Sahithi,
Any update on this?

Please also pay attention to these things:
>
> * indent the lines properly (Emacs does the right thing when you hit TAB)
> * don’t leave extraneous comments or dead code
> * make sure long expressions are broken up
>
> >> I am done with 2nd task out of given 4 tasks and that was included in my
> >> previous patch.
> >> I am currently working on 4th task.
> > I am able to filter lines.
> > I am trying out to*only* filter lines when “guix package” is used but
> > not when “guix build” by adding other port.
>
> The next step here would be to not print a dot for each line but to
> display a spinner instead, i.e. a sequence of characters that look like
> a spinning animation.  For each line the animation could be advanced by
> one (so it will spin really fast).
>
> Danny previously suggested this implementation:
>
>    https://lists.gnu.org/archive/html/guix-patches/2017-07/msg00068.html
>
> You may be able to take a part of that patch and adapt it.  The key here
> is really: keep track of the animation position and use backspace to
> delete the previously printed character before displaying the next.
>
> If you don’t like the spinner animation you could also pick one of
> these and try implementing them instead:
>
>    https://stackoverflow.com/questions/2685435/cooler-ascii-spinners
>
> Have fun!
>
> --
> Ricardo
>
>

[-- Attachment #2: Type: text/html, Size: 2731 bytes --]

^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-25 20:28                                                                                                                     ` Ricardo Wurmus
  2018-06-26 20:01                                                                                                                       ` Gábor Boskovits
@ 2018-06-29 22:51                                                                                                                       ` Sahithi Yarlagadda
  2018-07-03  2:29                                                                                                                         ` Sahithi Yarlagadda
  1 sibling, 1 reply; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-06-29 22:51 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1618 bytes --]

Hi


>> a spinning animation.  For each line the animation could be advanced by
>> one (so it will spin really fast).
>>
>> Danny previously suggested this implementation:
>>
>>    https://lists.gnu.org/archive/html/guix-patches/2017-07/msg00068.html
I have tried the Spinner code and it worked fine for me

https://paste.debian.net/1031385/
I used usleep so that I could to see the characters spinning with a
little delay to understand the code.


I tried to use the same for ui.scm, the  i replaced str with
spinner-port in handle-string code. I got the following
 15fb4d0>#<output: file 15fb4d0>#<output: file 15fb4d0>#<output: file
15fb4d0>#<output: file 15fb4d0>


I understood that i am working on a softport and unable to figure out
how to pass the string without invoking the display/write. I took a lot
of time and failed.


Here comes the actual part,
Later i discussed with #ArneBab in #guile who helped be finish the code.
I felt that invoking the spinner each time a string is triggered would
be sufficient and it doesnt matter whatever might be the string apart
from the expressions which are colorized, so went on to write the code
which i am submitting as a patch. For this i had to try a lot of new
syntaxes.


Now the spinner is working fine, build messages are colored and the
whole build process looks understandable to the user.

Actually im a bit excited!!!! to see the spinner code working and the
build output. Just wanted to share that to the community.


Please review the patch and push it to wip-sahithi if the progress is
correct.

> Have fun!
>
> --
> Ricardo
>
>

-- 
Regards
Sahithi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-Adding-Spinner-to-replace-the-Build-Messages.patch --]
[-- Type: text/x-patch; name="0001-guix-Adding-Spinner-to-replace-the-Build-Messages.patch", Size: 1321 bytes --]

From 9ff3dcf3a1f3b1b395659d956c15f07b5b028e38 Mon Sep 17 00:00:00 2001
From: Sahithi Yarlagadda <sahi@swecha.net>
Date: Sat, 30 Jun 2018 03:58:47 +0530
Subject: [PATCH]  guix: Adding Spinner to replace the Build Messages.

    * guix/ui.scm (handle-string): Calling the Spinner except for colored messages.
    (spin-str): New variable.
---
 guix/ui.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 88e5fa6b7..2bacffbf1 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1662,8 +1662,9 @@ unmodified input string."
               (colorize-string (match:substring m 5) 'RED))))
 
      ;; Didn’t match with any expression, returns back unmodified string.
-       str)))
-    (display message (current-error-port))))
+       (spin-str)
+	)))
+ (display (string-append (string #\backspace) message) (current-error-port))))
 
 (define colorful-build-output-port
   (make-soft-port
@@ -1677,5 +1678,12 @@ unmodified input string."
     (lambda () (display "@" (current-error-port))))
    "rw"))
 
+(define spin-str
+   (let ((chars (string->list "\\|/-"))
+       (index -1))
+       (lambda () (set! index (modulo (+ index 1)
+       (length chars)))
+       (list->string (list #\backspace(list-ref chars index) )))))
+
 
 ;;; ui.scm ends here
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Next steps
  2018-06-29 22:51                                                                                                                       ` Sahithi Yarlagadda
@ 2018-07-03  2:29                                                                                                                         ` Sahithi Yarlagadda
  0 siblings, 0 replies; 68+ messages in thread
From: Sahithi Yarlagadda @ 2018-07-03  2:29 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Hi

Please review the patch and assign me the what to do next.


On Saturday 30 June 2018 04:21 AM, Sahithi Yarlagadda wrote:
> Hi
>
>
>>> a spinning animation.  For each line the animation could be advanced by
>>> one (so it will spin really fast).
>>>
>>> Danny previously suggested this implementation:
>>>
>>>    https://lists.gnu.org/archive/html/guix-patches/2017-07/msg00068.html
> I have tried the Spinner code and it worked fine for me
>
> https://paste.debian.net/1031385/
> I used usleep so that I could to see the characters spinning with a
> little delay to understand the code.
>
>
> I tried to use the same for ui.scm, the  i replaced str with
> spinner-port in handle-string code. I got the following
>  15fb4d0>#<output: file 15fb4d0>#<output: file 15fb4d0>#<output: file
> 15fb4d0>#<output: file 15fb4d0>
>
>
> I understood that i am working on a softport and unable to figure out
> how to pass the string without invoking the display/write. I took a lot
> of time and failed.
>
>
> Here comes the actual part,
> Later i discussed with #ArneBab in #guile who helped be finish the code.
> I felt that invoking the spinner each time a string is triggered would
> be sufficient and it doesnt matter whatever might be the string apart
> from the expressions which are colorized, so went on to write the code
> which i am submitting as a patch. For this i had to try a lot of new
> syntaxes.
>
>
> Now the spinner is working fine, build messages are colored and the
> whole build process looks understandable to the user.
>
> Actually im a bit excited!!!! to see the spinner code working and the
> build output. Just wanted to share that to the community.
>
>
> Please review the patch and push it to wip-sahithi if the progress is
> correct.
>
>> Have fun!
>>
>> --
>> Ricardo
>>
>>

-- 
Regards
Sahithi

^ permalink raw reply	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2018-07-03  2:29 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <8ea5d026-fab9-7b12-198e-610ad7743cb2@swecha.net>
     [not found] ` <871sfxev9w.fsf@elephly.net>
     [not found]   ` <7626275c-3eee-bb05-ab9d-4c88ec6f0329@swecha.net>
     [not found]     ` <87r2nvjte6.fsf@elephly.net>
     [not found]       ` <5ab51417-b635-9725-9f48-3bc3f9b61fdf@swecha.net>
     [not found]         ` <87tvsko2wd.fsf@elephly.net>
     [not found]           ` <7290013c-990d-3f7d-d8db-38e090ed766a@swecha.net>
     [not found]             ` <87zi28kt82.fsf@elephly.net>
     [not found]               ` <8573e97d-d107-cde6-cd17-35f4ef6d2de3@swecha.net>
     [not found]                 ` <87k1takumm.fsf@elephly.net>
     [not found]                   ` <87o9hycwl6.fsf@elephly.net>
2018-05-11 21:16                     ` Status of Submitted Patches Sahithi Yarlagadda
2018-05-11 22:21                       ` Ricardo Wurmus
2018-05-12  7:50                         ` Ricardo Wurmus
2018-05-15 17:41                         ` Sahitihi
2018-05-20  9:40                           ` Ricardo Wurmus
2018-05-20 10:47                             ` Gábor Boskovits
2018-05-20 13:46                               ` Ricardo Wurmus
2018-05-23  7:53                             ` Sahitihi
2018-05-23  8:21                               ` Ricardo Wurmus
2018-05-24 17:16                                 ` Sahitihi
2018-05-24 20:00                                   ` Ricardo Wurmus
2018-05-25  3:43                                 ` Sahitihi
2018-05-25  5:18                                   ` Ricardo Wurmus
2018-05-25 17:59                                     ` Patch file for colorize module Sahitihi
2018-05-26  6:06                                       ` Sahitihi
2018-05-26  9:35                                         ` Ricardo Wurmus
2018-05-26 12:06                                           ` Sahitihi
2018-05-26 14:16                                             ` Ricardo Wurmus
2018-05-26 18:22                                               ` Sahitihi
2018-05-26 18:38                                                 ` Sahitihi
2018-05-26 21:20                                                   ` Ricardo Wurmus
2018-05-27 15:49                                                     ` Gábor Boskovits
2018-05-31  6:26                                               ` Fwd: " Ricardo Wurmus
2018-05-31 18:25                                                 ` Sahitihi
2018-05-31 19:28                                                   ` Ricardo Wurmus
2018-06-02 15:01                                                     ` Ricardo Wurmus
2018-06-03 14:18                                                     ` Sahitihi
2018-06-03 19:30                                                       ` Ricardo Wurmus
2018-06-04  7:48                                                         ` Sahitihi
2018-06-04 10:03                                                           ` Ricardo Wurmus
2018-06-04 18:51                                                             ` Sahitihi
2018-06-05 19:44                                                               ` Ricardo Wurmus
2018-06-06 19:49                                                                 ` Sahitihi
2018-06-06 20:06                                                                   ` Ricardo Wurmus
2018-06-06 21:20                                                                     ` Sahitihi
2018-06-06 21:28                                                                       ` Ricardo Wurmus
2018-06-07  3:29                                                                         ` Sahitihi
2018-06-07  5:22                                                                           ` Ricardo Wurmus
2018-06-07  7:47                                                                             ` Sahitihi
2018-06-07  8:25                                                                               ` Ricardo Wurmus
2018-06-08 17:01                                                                                 ` Sahitihi
2018-06-09  0:57                                                                                   ` Ricardo Wurmus
2018-06-09 18:08                                                                                     ` Sahitihi
2018-06-09 20:57                                                                                       ` Ricardo Wurmus
2018-06-11 12:14                                                                                         ` Sahitihi
2018-06-11 12:28                                                                                           ` Gábor Boskovits
2018-06-11 16:21                                                                                             ` Sahitihi
2018-06-12 14:12                                                                                               ` Ricardo Wurmus
2018-06-12 21:06                                                                                                 ` Sahitihi
2018-06-12 22:12                                                                                                   ` Ricardo Wurmus
2018-06-13 16:08                                                                                                     ` Sahithi Yarlagadda
2018-06-13 19:15                                                                                                       ` Ricardo Wurmus
2018-06-15 20:16                                                                                                         ` Sahitihi
2018-06-15 21:47                                                                                                           ` Next steps Ricardo Wurmus
2018-06-16 14:55                                                                                                             ` Sahitihi
2018-06-21 11:05                                                                                                               ` Ricardo Wurmus
2018-06-21 16:54                                                                                                                 ` Sahithi Yarlagadda
2018-06-25 20:13                                                                                                                   ` Sahithi Yarlagadda
2018-06-25 20:28                                                                                                                     ` Ricardo Wurmus
2018-06-26 20:01                                                                                                                       ` Gábor Boskovits
2018-06-29 22:51                                                                                                                       ` Sahithi Yarlagadda
2018-07-03  2:29                                                                                                                         ` Sahithi Yarlagadda
2018-06-24 18:25                                                                                                             ` Sahithi Yarlagadda
2018-06-24 20:22                                                                                                               ` Ricardo Wurmus
2018-06-24 20:33                                                                                                                 ` Sahithi Yarlagadda
2018-06-11 12:37                                                                                           ` Fwd: Re: Patch file for colorize module Ricardo Wurmus
2018-06-11 16:31                                                                                             ` Sahitihi
2018-06-04 11:41                                                         ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.