ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

ANSIescape

by aziz ST3

ANSI escape codes color highlighting for SublimeText 3

Details

Installs

  • Total 25K
  • Win 9K
  • Mac 9K
  • Linux 7K
Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6
Windows 1 7 2 8 1 2 2 0 7 4 1 4 1 3 0 5 1 2 2 2 0 2 2 1 3 2 7 0 1 5 5 3 1 5 4 1 5 11 2 5 6 1 3 3 4 1
Mac 0 2 5 3 2 1 2 0 3 2 2 3 5 4 1 0 6 5 4 2 2 0 2 7 5 3 3 1 0 1 4 4 4 5 0 1 4 8 7 3 3 1 1 2 3 1
Linux 2 3 4 2 6 2 0 2 3 6 1 1 3 0 1 2 3 4 2 6 4 2 2 4 1 5 5 2 0 4 5 3 1 0 1 1 1 5 8 4 2 1 1 3 4 2

Readme

Source
raw.​githubusercontent.​com

ANSI escape codes color highlighting for ST3

From time to time, you end up with a file in your editor that has ANSI escape codes in plain text which makes it really hard to read the content. Something that has been added to make your life easier, stands in your way and it's really annoying.

This plugin solves this annoying problem. Not by just removing the ANSI escape codes but by bringing back the color highlighting to those files.

Sublime ANSI Screenshot

Installation

You can install via Sublime Package Control
Or you can clone this repository into your SublimeText Packages directory and rename it to ANSIescape

Usage

When you see garbage in your editor change the syntax to ANSI and you're good!

The plugin works by detecting the syntax change event and marking ANSI color chars regions with the appropriate scopes matching the style defined in a tmTheme file.

Using this plugin as a dependency for your plugin/build output panel

If you're writing a plugin that builds something using a shell command and shows the results in an output panel, use this plugin! Do not remove ANSI codes, just set the syntax file of your output to Packages/ANSIescape/ANSI.sublime-syntax and ANSI will take care of color highlighting your terminal output.

Likewise, if you would like to display ANSI colors in your existing build-command output, you would only need to set ansi_color_build as the target and Packages/ANSIescape/ANSI.sublime-syntax as the syntax; for example:

// someproject.sublime-project
{
    "build_systems":
    [
        {
            /* your existing build command arguments */
            "name": "Run",
            "working_dir": "${project_path}/src",
            "env": {"PYTHONPATH": ".../venv/python2.7/site-packages"},
            "cmd": ["nosetests", "--rednose"],

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

If you use a custom build script and sub-programms don't output color, it could be that they assume the output has no colors. On Linux some applications can be forced to use colors by setting the environment variable CLICOLOR_FORCE=1. It is not recommended to set it permanently since it could cause issues if color is not supported and applications still output color. But in a SublimeANSI build you can use it for the usage in a Makefile build script, e.g.:

// someproject.sublime-project
{
    "build_systems":
    [
        {
            /* your existing build command arguments */
            "name": "Build",
            "working_dir": "${project_path}",
            "env": {"CLICOLOR_FORCE": "1"},
            "cmd": ["sh", "build.sh"],

            /*  add target and syntax */
            "target": "ansi_color_build",
            "syntax": "Packages/ANSIescape/ANSI.sublime-syntax"

             "variants":
            [
                {
                    "name": "Clean",
                    "cmd": ["sh", "build.sh", "clean"]
                }
            ]
        }
    ]
}

Killing the build process

If you want to kill build process during execution, use this command in sublime console (ctrl+`):

window.run_command("ansi_color_build", args={"kill": True})

You can also add key binding eg.:

// Preferences > Key Binding - User
[
    { "keys": ["ctrl+alt+c"], "command": "ansi_color_build", "args": {"kill": true} },
    // other key-bindings 
]

Formatting ANSI codes during build process

In order to format ANSI codes during building process change 'ANSI_process_trigger' in ansi.sublime-settings.

Customizing ANSI colors

All the colors used to highlight ANSI escape code can be customized through ansi.sublime-settings. Create a file named ansi.sublime-settings in your user directory, copy the content of default settings and change them to your heart's content.

Caveats:

  • ANSI views are read-only. But you can switch back to plain text to edit them if you want.
  • Does not render ANSI bold as bold, although we support it. You can assign a unique foreground color to bold items to distinguish them from the rest of the content.
  • Does not support dim, underscore, blink, reverse and hidden text attributes, which is fine since they are not supported by many terminals as well and their usage are pretty rare.

Known Issues

Not able to paste copied build message into a new buffer view

Just making the new view non-empty so the syntax won't be auto set. For example, type a new line before you paste.

License

Copyright 2014-2016 Allen Bargi. Licensed under the MIT License