hello world with colors

25 views
Skip to first unread message

Sanju Dutt

unread,
May 24, 2024, 4:36:03 AMMay 24
to fo...@jsoftware.com
Can a string's characters be output using random colors or perhaps by defining the colors using RGB values. Can it be done with / without viewmat or other graphics addon.
Will it work in jqt and jconsole (Windows) ?

Viktor Grigorov

unread,
May 24, 2024, 8:31:50 AMMay 24
to J Mailing List J
    }.,".;._2 S:0 LF,2!:0'uni -c -f ''%(dec)'' i "''\033[48;2;0;0;0m\033[38;2;255;0;0mHello, \033[48;2;255;0;0m\033[38;2;0;0;0mworld.\033[0m''"'

I don't know of any J primitives or stdlib parts of sentence, that use color. That said, I use some ANSI escape sequences, like bell, frequently.[1] 'echo -n' and 'printf %b\\n' would allow for that.

Using uni[2], with "uni -c -f '%(dec)' i $'\033[48;2;0;0;0m\033[38;1;255;0;0m'" one can get the decimal, ASCII values of the message.
}.,".;._2 S:0 LF,2!:0'uni -c -f ''%(dec)'' i "''\033[48;2;0;0;0m\033[38;2;255;0;0mHello, \033[48;2;255;0
   a i.^:(_1) 72 101 108 108 111 44 32 119 111 114 108 100 46 # should be "Hello, world." in bold and red on black, but isn't because escaping is botched
Hello, world.

J's stdlib echo doesn't handle escape sequences.
zsh and bash have a $RANDOM parameter, that can be used to receive a ??-bit number. A script for random color pairings would be easier in a terminal emulator, since it already knows about colors, compared to most programming languages, which most often do not.

[1] https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences
[2] https://github.com/arp242/uni




May 24, 2024, 08:36 by dut...@gmail.com:

> Can a string's characters be output using random colors or perhaps by defining the colors using RGB values. Can it be done with / without viewmat or other graphics addon.
> Will it work in jqt and jconsole (Windows) ?
>
>
>
>
> To unsubscribe from this group and stop receiving emails from it, send an email to > forum+un...@jsoftware.com> .
>

Raul Miller

unread,
May 24, 2024, 12:09:21 PMMay 24
to fo...@jsoftware.com
There's many possibilities here. For example, in jqt try:

wd 'sm html *<br><span style="color:red">hello world</span>'

Or, for example take a look at
https://code.jsoftware.com/wiki/Guides/Text_Titles

A variant which doesn't use plot and opens in its own window (and also
is a bit more involved than "hello world') might be
https://rosettacode.org/wiki/Matrix_digital_rain#J

I hope this helps,

--
Raul

On Fri, May 24, 2024 at 1:36 AM Sanju Dutt <dut...@gmail.com> wrote:
>
> Can a string's characters be output using random colors or perhaps by defining the colors using RGB values. Can it be done with / without viewmat or other graphics addon.
> Will it work in jqt and jconsole (Windows) ?
>

Sanju Dutt

unread,
May 25, 2024, 12:19:20 AMMay 25
to fo...@jsoftware.com
I see. Thanks for your responses, Viktor and Raul.
Reply all
Reply to author
Forward
0 new messages