Sublime Forum

Build with colored output

#1

I’ve read other articles about getting the Build window to show colors. My test runner shows colors from bash, but not in the Sumblime3 build window. What do I need to do? Read below to see what I’ve tried.

Without modification, the output is this

Running CircularBuffer_tests
.
e[32;1mOK (1 tests, 1 ran, 0 checks, 0 ignored, 0 filtered out, 0 ms)e[m

The ANSI escape sequences are there.

When I add this to my project:

    "build_systems":
    [
        {
            "name": "cybe-dojo-start-points",
            "working_dir": "${project_path}",
            "cmd": ["make"],

            /*  added for ANSI */
            "target": "ansi_color_build",
            "syntax": "Packages/ANSIescape/ANSI.sublime-syntax"
        }
    ]

I get this. The escape codes are not visible and the color is not changed.

Running CircularBuffer_tests
.
OK (1 tests, 1 ran, 0 checks, 0 ignored, 0 filtered out, 0 ms)

The package ANSIescape is installed and found. If I put in a typo in the package name, I get an error from Sublime.

Ideas?

1 Like

#2

I will call it a bug. Fixed in the next release. Should available in a few hours.

1 Like

#3

Sounds good Jack. I’ll check it ASAP.

0 Likes

#4

Also, is there a way to not show error info provided by sublime.

For example

Running utilities_tests

CircularBufferTest.cpp:25: error: Failure in TEST(CircularBuffer, Create)
	Start here

.
Errors (1 failures, 1 tests, 1 ran, 1 checks, 0 ignored, 0 filtered out, 1 ms)

make[1]: *** [all] Error 1
make: *** [all] Error 2
[Finished in 0.1s with exit code 2]
[cmd: ['make']]
[dir: /Users/james/repos/github/tdd-ec-workspace]
[path: /Users/james/google-cloud-sdk/bin:/Users/james/.rvm/gems/ruby-2.6.0/bin:/Users/james/.rvm/gems/ruby-2.6.0@global/bin:/Users/james/.rvm/rubies/ruby-2.6.0/bin:/Users/james/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/james/android/sdk/tools:/Users/james/android/sdk/platform-tools:/Users/james/.rvm/bin]

I’d like to turn off everything including and after [cmd: ['make']]
Thanks

0 Likes

#5

The standard exec command used in build systems supports an argument named quiet that you can set to true to turn the diagnostic output off. It looks like the package you’re using is wrapping exec in a way where that will still work, so that may be a viable solution for you.

{
    "name": "cybe-dojo-start-points",
    "working_dir": "${project_path}",
    "cmd": ["make"],
    "quiet": true,

    /*  added for ANSI */
    "target": "ansi_color_build",
    "syntax": "Packages/ANSIescape/ANSI.sublime-syntax"
}

Note however that it stops all debug output, so not only will it not display the command executed and so on, it also won’t display the [Finished] part (on success or on failure), which it sounds like you may still want to see. On the other hand, if you’re running tools that generate obvious errors when they fail, that may be less of a limitation.

1 Like

#6

Excellent! Thank you.

0 Likes

#7

May I ask a question?

This thread made me discover the ANSIEscape package. Really cool! I immediately added colors to my build scripts.
But now my build panel inside the ST’s window has black background white foreground text color. Why? How can I keep my theme’s colors, black text on white background?

Thanks

0 Likes

#8

That’s not possible because it’s how ANSIEscpae works. Your color scheme won’t have scopes for highlighting those colors.

1 Like

#9

Ok, thanks. I can live with that.

0 Likes

#10

Hey! I found that there are settings for that. You may config fg/bg and restart your ST. Not really using your color scheme though.

1 Like

#11

Thanks a lot! It is an acceptable compromise.

I have to edit ~/.config/sublime-text-3/Packages/User/ANSIescape/ansi.sublime-color-scheme . No restart required, the build panels gets updated real-time saving that file. It is also necessary to edit all the backgrounds for any ANSI escape sequence, not a problem obviously.

1 Like

#12

That file is auto generated. You should not modify it but modify your settings instead.

1 Like

#13

I downloaded 3208 and the color is working. Thanks!

1 Like

#14

I usually disable colorisation in build output because it seems that ANSIescape easily gets confused, so I just tried to reenable colors with pytest again with ST v3208, but the result is still somewhat obfuscated:

Not sure whether that is because of broken ouput from pytest, but the output looks fine when run directly from the shell.

BTW, the lines in the output are wrapped, what exact setting controls that?

0 Likes

#16

Would it happen when ANSI_process_trigger is set to on_finish?

0 Likes

#17

Ah, you are right, if I change "ANSI_process_trigger": "on_data" to "ANSI_process_trigger": "on_finish", the colorisation works fine. Thanks!

0 Likes

#18

I guess on_data randomly gets a malformed (cut) color code during the build execution… :frowning: But on_finish is not good if the build process takes a long time.

0 Likes