• Stars
    star
    221
  • Rank 179,773 (Top 4 %)
  • Language
    Python
  • Created almost 10 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ANSI escape codes color highlighting for SublimeText 3

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

More Repositories

1

PlainTasks

An opinionated todo-list plugin for Sublime Text editor (version 2 and 3)
Python
3,287
star
2

tmTheme-Editor

Color scheme editor for SublimeText, Textmate and a bunch of other text editors
HTML
1,686
star
3

SublimeFileBrowser

Ditch sidebar and browse your files in a normal tab with keyboard, like a pro!
Python
394
star
4

PlainNotes

Simple and pleasant note taking for SublimeText
Python
273
star
5

SublimeHyperClick

Quickly and easily jump between your files. The missing part of Go to definition functionality in Sublime.
Python
211
star
6

dotfiles

My Unix environment
Shell
163
star
7

BetterFindBuffer

Adds a couple of missing features to SublimeText 3 Find Results buffer
Python
107
star
8

knockdown

Github flavored Markdown for SublimeText and a custom theme for writing markdown
JavaScript
89
star
9

GoogleReader-OSXLionUI

REST IN PEACE GOOGLE READER! A user style for new google reader UI that makes you feel right at home
JavaScript
88
star
10

virastar

cleanning up Persian text!
Ruby
81
star
11

DistractionFreeWindow

SublimeText "Distraction free mode" but not full-screen! A windowed UI is more manageable and accessible yet it can be simple and sublime!
Python
46
star
12

jalalidate

A library for working with Jalali Calendar (a.k.a Persian Calendar)
Ruby
42
star
13

SublimeSyntaxConvertor

Converts tmLanguage to sublime-syntax
Ruby
37
star
14

farsifu

A toolbox for developing ruby applications in Persian (Farsi) language, see readme for features
Ruby
23
star
15

SublimeSyncedSidebarBg

Changes the sidebar theme based on active view's color scheme
Python
14
star
16

sublimeText3-Userfiles

My text-editor config files
Python
14
star
17

sublimeText2-Userfiles

I'm not updating this repo anymore, I've moved to SublimeText 3 https://github.com/aziz/sublimeText3-Userfiles
Python
12
star
18

sublime-mini-ui

HTML
10
star
19

tmTheme-Editor-Parser

Ruby
5
star
20

Things

A online replica of awesome Mac OSX task management app Things, a personal practice for development of desktop like applications
JavaScript
4
star
21

html5-slides-rtl

This is a fork of google's html5slides project with right to left support
JavaScript
3
star
22

PlasticAB

Porting my plasticCodeWrap textmate/sublime color-scheme to vs-code
3
star
23

sublime-history

Python
2
star
24

latex-template

my personal latex templates
TeX
2
star
25

pingilish

Converting Farsi to Pingilish (Farsi written in Latin alphabets) and Pingilish to Farsi
2
star
26

SublimeCucumberSteps

Python
1
star
27

atom-plastic-code-wrap-syntax

CSS
1
star
28

SublimeTheme

JavaScript
1
star
29

ignore_words

Ignore words for spell check in Sublime 3
Python
1
star
30

textmate

All textmate bundles I use, managed by git submodules
Ruby
1
star
31

parsmark

Persian flavour of MultiMarkdown
1
star