Question

I use a build system in Sublime Text 3 that outputs color by default and I would like an easy way to strip that color out of the output in the build window.

Here is my sublime-project file:

{
    "folders":
    [
        {
        "follow_symlinks": true,
        "path": ".",
        "folder_exclude_patterns": ["obj", "bin", "build"]
        }
    ],
    "build_systems":
    [
        {
        "name": "boost build",
        "path" : "/usr/local/bin:/usr/bin:/bin",
        "cmd": ["bash", "-c", "( cd ${project_path} && exec b2 )"]
        }
    ]
}

How can I accomplish what I'm trying to do?

Was it helpful?

Solution

I'm not sure how to do this on systems other than Mac OS X, but I found the easiest way to do what you're trying to is by piping the output through sed to strip out the escape sequences.

Here is your build command modified accordingly:

"cmd": ["bash", "-c", "( cd ${project_path} && exec b2 | sed 's/\\ESC\\\\[[0-9;]*m//g' )"]

Now, unfortunately, I have no idea how to copy and paste the ESC character that Sublime Text uses to display an escape character, but I basically just copied that from the console window and placed it where ESC is written above. I couldn't figure out any other method of providing the escape character and I tried almost every combination of \033 and \x1B I could think of.

I didn't want to have to include a screenshot, but I'll provide one for the sake of clarity regardless:

Escape character picture

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top