20

How can you get color into the ST3 build output window?

I'm using gccfilter to colorize my build output, but ST3 just displays the raw escape sequences. Is there any way to get it to process them? Or to remove gccfilter and just get ST3 to colorize the output (e.g. just grep on warning & error would be fine)?

2 Answers 2

16

Recent versions of ST3's Makefile build system (as described in the Make.sublime-build file) already contain a syntax definition which produces colorized output.

If you're not happy with that, here's what you can do as an alternative and generally working approach if you have a build system which produces ANSI colors in a terminal and you want to have them show in the build output panel of Sublime Text 3.

This is how I did it in my Sublime Text 3 installation for RSpec, but I think it is perfectly applicable in any case with a tool producing color in a regular console/TTY:

1. Force your build system to output colors even if it's not outputting to a TTY.

This depends on the build system. For example, for Ruby and RSpec, you might create an .rspec file in your project with the following contents:

--color --tty

In your case, you already have a build system which produces output with ANSI color escape sequences.

2. Install the ANSIescape (SublimeANSI) package

It's recommended to install it via Package Control. See the repo of the package for installation and configuration instructions.

3. Create a new build system definition in Sublime Text and configure it to recognize ANSI colors

For example, here is the contents of my Colorized RSpec.sublime-build build system:

{
    "cmd": ["rspec", "-I ${file_path}", "$file"],
    "file_regex": "# ([A-Za-z:0-9_./ ]+rb):([0-9]+)",
    "working_dir": "${project_path:${folder:${file_path}}}",
    "selector": "source.ruby.rspec",
    // Recognize ANSI colors in the output
    "target": "ansi_color_build",
    "syntax": "Packages/ANSIescape/ANSI.tmLanguage"
}

The last two configuration options are taken from SublimeANSI's readme. You can apply this to your build system for Make. You can base it on the current version of the Make.sublime-build file from Sublime Text 3's packages.

4. Build your file/project using the newly created build system.

Use the "Build with..." menu to pick the new build system. On OS X this is Cmd + Shift + B. Subsequent builds with Cmd + B will use this last picked build system.

Here's how it looks:

enter image description here

1
  • 1
    Unluckily, ANSIEscape has some limitation in parsing the ANSI escape codes, so not all output will benefit. Here are some limitation I've found: * Seting the background after the forground is not interperted. * Using two digits (like in <ESC>[01m) is not parsed corectly * Some codes used to clean line (notably: <ESC>[K) aren't parsed. This makes this method not fully suitable for - for example - GCC Oct 9, 2017 at 11:06
5

There's currently no way to make the ST3 console parse colors that I have found. This would need to be discussed with the author. I have noticed before that the console always has monochromatic output. ST3 currently only uses the colors that are provided with the theme that you have applied to it.

Only way to get rid of the escape sequences would be to filter them out before the output hits Sublime.

2
  • 1
    Heh, I could easily filter them out by just not using gccfilter.. I just want COLOR!!
    – Yeraze
    Jan 10, 2014 at 21:18
  • Yeah, I wish it was possible. Perhaps pushing it to the author will get it done.
    – Sly
    Jan 10, 2014 at 22:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .