morassman / process-palette

Atom package for running parameterised shell commands
MIT License
33 stars 17 forks source link

Add support for ANSI escape sequences (e.g. colors) #5

Open Pauan opened 9 years ago

Pauan commented 9 years ago

I tried many different script runners, including run-in-terminal, termrk, terminal-panel, term, quantum-shell, etc.

Sadly, except for term, they're all broken. So far, yours is the best for fulfilling my particular needs.


However, there is one feature I would like: the ability to show ANSI color escapes.

Here is how it looks when I run the command in my terminal: (screenshot)

And here is how it looks when I run the same command in process-palette: (screenshot)

morassman commented 9 years ago

I'd really like to do this. Relative to the other issues I'm going to give this one a lower priority, but at some point I'd like to start looking into it.

Pauan commented 9 years ago

That's fine, I understand that this is a "nice-to-have" feature, and not a necessity.

tty.js has support for ANSI colors, maybe it would be possible to grab their implementation and use it?

morassman commented 8 years ago

@toddmazierski recently added support for ANSI colour escape sequences. v0.5.4 includes it. Try it out. It might not give you the output as shown in the screenshot from your terminal. This change should only add colours, but other control sequences, such as moving the cursor around on the screen, are not supported.

Pauan commented 8 years ago

I just upgraded to Atom version 1.2.4 and process-palette version 0.5.4, but the colors are not showing up in process-palette: it's the same as before.

morassman commented 8 years ago

Ok. Thanks for testing it. I've been testing it a bit more myself and the only time I actually get colours out is if I do an "echo" with escape sequences hard-coded in, but when running any other process I don't get any colours either. I'll dig a bit into it...

toddmazierski commented 8 years ago

Hi @Pauan and @morassman,

By default, most command line utilities (correctly) automatically disable colors if they detect a non-interactive (non-tty) shell. Most, however, offer arguments or config flags to override this behavior.

For example, for colors to appear for npm, you can pass --color=always (documentation):

screen shot 2015-11-25 at 10 06 23 am
morassman commented 8 years ago

That makes sense. Thanks @toddmazierski. @Pauan did suggest I look at tty.js. Perhaps it fools the process into thinking that it's an interactive shell, which then has the desired effect.

FYI. Process Palette uses shelljs to run commands and I saw that there has been a feature request for this. If this gets done for shelljs it should "just work" thanks to the changes you made. When I get time I'll also look at how tty.js did things.

PS. From your screenshot it looks like it would be useful to be able to configure the background colour. Perhaps making the background colour black by default would also help.

Pauan commented 8 years ago

@toddmazierski Thank you for the explanation.

Using npm --color=always run-script build and webpack --colors does work.


@morassman Yes, the ability to customize the background color and font color would be very nice.

I think the default should be black and white, respectively.


Also, I noticed this: (screenshot)

It's including the ANSI color escapes (e.g. [34m) in the output.

I'm not sure what the best way to fix this is: either colorizing the output so it displays proper colors, or stripping out the ANSI color escapes.

lucidNTR commented 8 years ago

+1 for showing correct colors in process palette, extremely helpfull for running large test suites...