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