ANSI Escape Codes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ANSI Escape Codes

Ryland Taylor-Almanza
I'm trying to make a console-based program that makes use of ANSI
escape codes. I can't seem to figure out how to go about printing a
string object formatted with ANSI escape codes. I've tried the
following.

'\x1b[31mHi' displayNl

This prints the entire string, including the escape code, without any
formatting. I would have expected this to print "Hi" in red (and then
everything else in the console after that, as I didn't include the
escape code to reset the color.)

After googling a bit, I was able to find a couple issues where people
were trying to produce things like newlines using "\n". Most of the
answers were using the Transcript object's cr method, but I didn't
find anything about colors in the textCollector class.

It looks like it shouldn't be all that hard to create my own module in
C to achieve this functionality, but I'd like to know if there's a
better way first.

I'm aware of the ncurses bindings, but I'm not sure that'd be
practical for just making certain pieces of text in the program
colored. So, is there a standard way of outputting colored text to the
terminal in GNU Smalltalk using ANSI escape sequences?

Thanks!

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Paolo Bonzini-2
Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
> I'm trying to make a console-based program that makes use of ANSI
> escape codes. I can't seem to figure out how to go about printing a
> string object formatted with ANSI escape codes. I've tried the
> following.
>
> '\x1b[31mHi' displayNl

You can use formatted strings to put the Escape character in place:

('%1[31mHi' % #($<16r1b>)) displayNl.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Ryland Taylor-Almanza
This seems to be giving me the following error.

stdin:1: parse error, expected '>'

My apologies if I'm missing something. I'm a bit new to smalltalk

On Tue, Jul 8, 2014 at 1:13 AM, Paolo Bonzini <[hidden email]> wrote:

> Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
>
>> I'm trying to make a console-based program that makes use of ANSI
>> escape codes. I can't seem to figure out how to go about printing a
>> string object formatted with ANSI escape codes. I've tried the
>> following.
>>
>> '\x1b[31mHi' displayNl
>
>
> You can use formatted strings to put the Escape character in place:
>
> ('%1[31mHi' % #($<16r1b>)) displayNl.
>
> Paolo
>
> _______________________________________________
> help-smalltalk mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-smalltalk

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Paolo Bonzini-2
Il 08/07/2014 18:29, Ryland Taylor-Almanza ha scritto:
> This seems to be giving me the following error.
>
> stdin:1: parse error, expected '>'

You're probably using an older version of GNU Smalltalk.  What version
are you running on ("Smalltalk version" will tell you).

Paolo

> My apologies if I'm missing something. I'm a bit new to smalltalk
>
> On Tue, Jul 8, 2014 at 1:13 AM, Paolo Bonzini <[hidden email]> wrote:
>> Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
>>
>>> I'm trying to make a console-based program that makes use of ANSI
>>> escape codes. I can't seem to figure out how to go about printing a
>>> string object formatted with ANSI escape codes. I've tried the
>>> following.
>>>
>>> '\x1b[31mHi' displayNl
>>
>>
>> You can use formatted strings to put the Escape character in place:
>>
>> ('%1[31mHi' % #($<16r1b>)) displayNl.
>>
>> Paolo
>>
>> _______________________________________________
>> help-smalltalk mailing list
>> [hidden email]
>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>
> _______________________________________________
> help-smalltalk mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Ryland Taylor-Almanza
Looks like I'm running 3.2.5, which came from my system's repos. Is it
recommended that I use the 3.3 alpha?

On Tue, Jul 8, 2014 at 10:26 AM, Paolo Bonzini <[hidden email]> wrote:

> Il 08/07/2014 18:29, Ryland Taylor-Almanza ha scritto:
>
>> This seems to be giving me the following error.
>>
>> stdin:1: parse error, expected '>'
>
>
> You're probably using an older version of GNU Smalltalk.  What version are
> you running on ("Smalltalk version" will tell you).
>
> Paolo
>
>
>> My apologies if I'm missing something. I'm a bit new to smalltalk
>>
>> On Tue, Jul 8, 2014 at 1:13 AM, Paolo Bonzini <[hidden email]> wrote:
>>>
>>> Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
>>>
>>>> I'm trying to make a console-based program that makes use of ANSI
>>>> escape codes. I can't seem to figure out how to go about printing a
>>>> string object formatted with ANSI escape codes. I've tried the
>>>> following.
>>>>
>>>> '\x1b[31mHi' displayNl
>>>
>>>
>>>
>>> You can use formatted strings to put the Escape character in place:
>>>
>>> ('%1[31mHi' % #($<16r1b>)) displayNl.
>>>
>>> Paolo
>>>
>>> _______________________________________________
>>> help-smalltalk mailing list
>>> [hidden email]
>>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>
>>
>> _______________________________________________
>> help-smalltalk mailing list
>> [hidden email]
>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Paolo Bonzini-2
Il 08/07/2014 19:58, Ryland Taylor-Almanza ha scritto:
> Looks like I'm running 3.2.5, which came from my system's repos. Is it
> recommended that I use the 3.3 alpha?

No, my mistake---it's just

  ('%1[31mHi' % #($<16r1B>)) displayNl.

with an uppercase B.

Paolo

> On Tue, Jul 8, 2014 at 10:26 AM, Paolo Bonzini <[hidden email]> wrote:
>> Il 08/07/2014 18:29, Ryland Taylor-Almanza ha scritto:
>>
>>> This seems to be giving me the following error.
>>>
>>> stdin:1: parse error, expected '>'
>>
>>
>> You're probably using an older version of GNU Smalltalk.  What version are
>> you running on ("Smalltalk version" will tell you).
>>
>> Paolo
>>
>>
>>> My apologies if I'm missing something. I'm a bit new to smalltalk
>>>
>>> On Tue, Jul 8, 2014 at 1:13 AM, Paolo Bonzini <[hidden email]> wrote:
>>>>
>>>> Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
>>>>
>>>>> I'm trying to make a console-based program that makes use of ANSI
>>>>> escape codes. I can't seem to figure out how to go about printing a
>>>>> string object formatted with ANSI escape codes. I've tried the
>>>>> following.
>>>>>
>>>>> '\x1b[31mHi' displayNl
>>>>
>>>>
>>>>
>>>> You can use formatted strings to put the Escape character in place:
>>>>
>>>> ('%1[31mHi' % #($<16r1b>)) displayNl.
>>>>
>>>> Paolo
>>>>
>>>> _______________________________________________
>>>> help-smalltalk mailing list
>>>> [hidden email]
>>>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>>
>>>
>>> _______________________________________________
>>> help-smalltalk mailing list
>>> [hidden email]
>>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>>
>>
>


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: ANSI Escape Codes

Paolo Bonzini-2
Il 08/07/2014 23:02, Ryland Taylor-Almanza ha scritto:
> Looks like it works! Thanks Paolo! I don't really understand what
> that's doing, though. Do you have any resources you could link that
> explain what that whole (<string> % #($<16r1B>)) bit does?

"%" is just a so called "interpolation" operator.  It looks for
sequences that look like %number and replaces them with elements from
the array on the right of the %.

In this case the array has one element and that element is a character
with ASCII code 1B (in hexadecimal).

So the %1 in "%1[31mHi" is replaced with the escape character and printed.

Paolo

> On Tue, Jul 8, 2014 at 12:58 PM, Paolo Bonzini <[hidden email]> wrote:
>> Il 08/07/2014 19:58, Ryland Taylor-Almanza ha scritto:
>>
>>> Looks like I'm running 3.2.5, which came from my system's repos. Is it
>>> recommended that I use the 3.3 alpha?
>>
>>
>> No, my mistake---it's just
>>
>>  ('%1[31mHi' % #($<16r1B>)) displayNl.
>>
>> with an uppercase B.
>>
>> Paolo
>>
>>
>>> On Tue, Jul 8, 2014 at 10:26 AM, Paolo Bonzini <[hidden email]> wrote:
>>>>
>>>> Il 08/07/2014 18:29, Ryland Taylor-Almanza ha scritto:
>>>>
>>>>> This seems to be giving me the following error.
>>>>>
>>>>> stdin:1: parse error, expected '>'
>>>>
>>>>
>>>>
>>>> You're probably using an older version of GNU Smalltalk.  What version
>>>> are
>>>> you running on ("Smalltalk version" will tell you).
>>>>
>>>> Paolo
>>>>
>>>>
>>>>> My apologies if I'm missing something. I'm a bit new to smalltalk
>>>>>
>>>>> On Tue, Jul 8, 2014 at 1:13 AM, Paolo Bonzini <[hidden email]> wrote:
>>>>>>
>>>>>>
>>>>>> Il 08/07/2014 02:50, Ryland Taylor-Almanza ha scritto:
>>>>>>
>>>>>>> I'm trying to make a console-based program that makes use of ANSI
>>>>>>> escape codes. I can't seem to figure out how to go about printing a
>>>>>>> string object formatted with ANSI escape codes. I've tried the
>>>>>>> following.
>>>>>>>
>>>>>>> '\x1b[31mHi' displayNl
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> You can use formatted strings to put the Escape character in place:
>>>>>>
>>>>>> ('%1[31mHi' % #($<16r1b>)) displayNl.
>>>>>>
>>>>>> Paolo
>>>>>>
>>>>>> _______________________________________________
>>>>>> help-smalltalk mailing list
>>>>>> [hidden email]
>>>>>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> help-smalltalk mailing list
>>>>> [hidden email]
>>>>> https://lists.gnu.org/mailman/listinfo/help-smalltalk
>>>>>
>>>>
>>>
>>
>


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk