aziz / SublimeANSI

ANSI escape codes color highlighting for SublimeText 3
222 stars 40 forks source link

Make default color mapping support OSX Clang #23

Open kavika13 opened 8 years ago

kavika13 commented 8 years ago

Clang on OSX outputs escape sequences that look like this:

<ESC>[0;1;31m

I don't know escape sequences well enough to know if clang is just flat out wrong, or if it is expecting more complete ANSI support. Either way, the default settings only match color escape sequences with two values.

Here's a mapping that seemed to work for me:

{"scope": "black", "code": "\\x1b\\[(0;(0;)?)?30m", "color": "#000000"},
{"scope": "black_light", "code": "\\x1b\\[(0;)?1;30m", "color": "#686868"},
{"scope": "red", "code": "\\x1b\\[(0;(0;)?)?31m", "color": "#c71e12"},
{"scope": "red_light", "code": "\\x1b\\[(0;)?1;31m", "color": "#ff6f6b"},
{"scope": "green", "code": "\\x1b\\[(0;(0;)?)?32m", "color": "#00c120"},
{"scope": "green_light", "code": "\\x1b\\[(0;)?1;32m", "color": "#67f86f"},
{"scope": "yellow", "code": "\\x1b\\[(0;(0;)?)?33m", "color": "#c7c327"},
{"scope": "yellow_light", "code": "\\x1b\\[(0;)?1;33m", "color": "#fffa72"},
{"scope": "blue", "code": "\\x1b\\[(0;(0;)?)?34m", "color": "#0a2fc4"},
{"scope": "blue_light", "code": "\\x1b\\[(0;)?1;34m", "color": "#6a76fc"},
{"scope": "magenta", "code": "\\x1b\\[(0;(0;)?)?35m", "color": "#c839c5"},
{"scope": "magenta_light", "code": "\\x1b\\[(0;)?1;35m", "color": "#ff7cfd"},
{"scope": "cyan", "code": "\\x1b\\[(0;(0;)?)?36m", "color": "#01c5c6"},
{"scope": "cyan_light", "code": "\\x1b\\[(0;)?1;36m", "color": "#68fdfe"},
{"scope": "white", "code": "\\x1b\\[(0;(0;)?)?(37)?m", "color": "#c7c7c7"},
{"scope": "white_light", "code": "\\x1b\\[(0;)?1;37m", "color": "#ffffff"},
{"scope": "_bold", "code": "\\x1b\\[(0;(0;)?)?1m", "color": "#ffffff", "font_style": "bold"}
kavika13 commented 8 years ago

This file is not perfect though :) I think it has problems with bold/unbold. I can upload a sample clang output if that is useful.

PurplePowder commented 8 years ago

If someone is interested, I made a fork without regular expressions but with a really simple ANSI parser. It solves problem with clang output. You can find it here https://github.com/PurplePowder/SublimeANSI

kavika13 commented 8 years ago

It works pretty well out of the box. This also looks like way less of a headache to understand and configure.

I had user settings already, and it puked on them, even if I emptied the file and saved it. Is there something you can do to make error recovery on a bad user (not default) settings file slightly better? It seems to default to an "all grey" theme when it dies on user configuration, instead of falling back.

Of course, once I copied the default settings to the user settings path it worked :)

I have about 3 feature requests now, but I think it makes more sense to focus on verifying if your branch is stable before worrying about that.

PurplePowder commented 8 years ago

I had user settings already, and it puked on them, even if I emptied the file and saved it. Is there something you can do to make error recovery on a bad user (not default) settings file slightly better?

Fixed. Now when plugin founds out that some required color isn't described in settings, it simply doesn't colorize it, so default color is used

heyer2 commented 4 years ago

This is still an issue.

jfcherng commented 4 years ago

You can file a PR or use https://packagecontrol.io/packages/Terminus instead nowadays.