chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.76k stars 414 forks source link

Colorful output on terminal #8321

Closed nimitbhardwaj closed 1 week ago

nimitbhardwaj commented 6 years ago

Just want that there are some functions which can write colourfully on terminal console. Because mostly all terminals support ASCII schemes, so it can be done easily, just I tried this

writeln("\x1b[34m Hello, world!\x1b[0m");

This wrote Hello World in blue, so I wanted something like this writeBlueln("Hello");, this will write Hello in Blue, similarly for other colors, and also there is an alternative, writeln("%sB Hello %eB"); , this will write again Hello in blue, but here %sB is tag for starting of blue, and %eB is for ending of blue, I think both types of functions can be a good layer on writeln and other writing functions of type.

How about implementing it, an easy think to implement can be useful often for command line applications, there are many such useful modules in python too, like colorama etc. So It can be useful.

ben-albrecht commented 6 years ago

I think you could pursue this as a mason package in a separate repository.

Here is an example I made a while ago, if that helps.

ben-albrecht commented 6 years ago

I don't think this would be a good feature for writef for a few reasons:

I think this would be a nice library to have as a mason package.

A good step forward in that direction would be to create a separate repository for this library and create an issue to discuss the design there. You could request feedback on the design from the developer community by emailing the chapel-developers mailing list.

ben-albrecht commented 6 years ago

I am reopening this to give others a chance for opinions...

bradcray commented 6 years ago

I like the Colors.chpl sketch that Ben points to above as a means of switching colors within a single write() call in a clear manner. I worry a little about adding more control strings into writef() due to the number that already exist there, at least without a clear precedent in a popular language that has gained a foothold (I'm not aware of one).

nimitbhardwaj commented 6 years ago

OK, what will be better, making the new module, include in mason, or edit the writef, write, writeln etc functions to support colors in some easy way then to write those weird ANSI codes.

nimitbhardwaj commented 6 years ago

Yes, I feel that it would be great for Mason, implementing for standard writing functions will be mess here, so implementing using a new package in Mason will likely to be best.

nimitbhardwaj commented 6 years ago

Hey, for console output of colors I made the repo here. Please have a check there.

nimitbhardwaj commented 6 years ago

And made the PR at the mason-registry too for the same

jabraham17 commented 1 week ago

Closing, the PR https://github.com/chapel-lang/mason-registry/pull/12 to add this to mason was never merged due to inactivity and I think the consensus here is that this would make a great mason package, not a standard chapel feature