|
| 1 | +*AnsiEsc.txt* Ansi Escape Sequence Visualization Jul 21, 2020 |
| 2 | + |
| 3 | +Author: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
| 4 | + (remove NOSPAM from Campbell's email first) |
| 5 | +Copyright: (c) 2004-2017 by Charles E. Campbell *AnsiEsc-copyright* |
| 6 | + The VIM LICENSE applies to AnsiEsc.vim and AnsiEsc.txt |
| 7 | + (see |copyright|) except use "AnsiEsc" instead of "Vim". |
| 8 | + No warranty, express or implied. Use At-Your-Own-Risk. |
| 9 | + |
| 10 | +============================================================================== |
| 11 | +1. Contents *AnsiEsc* *AnsiEsc-contents* |
| 12 | + 1. Contents ...................................|AnsiEsc-contents| |
| 13 | + 2. AnsiEsc Manual ...................................|AnsiEsc| |
| 14 | + 3. AnsiEsc Method ...................................|AnsiEsc-Method| |
| 15 | + 4. AnsiEsc History ...................................|AnsiEsc-history| |
| 16 | + |
| 17 | +============================================================================== |
| 18 | +2. Manual *AnsiEsc-manual* |
| 19 | + |
| 20 | + |
| 21 | + CONCEAL~ |
| 22 | + The best option: for this, your vim must have +conceal. Try either > |
| 23 | + :version |
| 24 | + :echo has("conceal") |
| 25 | +< if you have vim v7.3. Your vim needs to have been compiled |
| 26 | + for "big" or "huge" and to support syntax highlighting. |
| 27 | + |
| 28 | + Vim: (v7.2 or earlier) -- ansi escape sequences themselves are Ignore'd~ |
| 29 | + Ansi escape sequences have the expected effect on subsequent |
| 30 | + text, but the ansi escape sequences themselves still take up |
| 31 | + screen columns. The sequences are displayed using "Ignore" |
| 32 | + highlighting; depending on your colorscheme, this should either |
| 33 | + make the sequences blend into your background or be visually |
| 34 | + suppressed. If the sequences aren't suppressed, you need to |
| 35 | + improve your colorscheme! |
| 36 | + |
| 37 | + *:AnsiEsc* |
| 38 | + USAGE~ |
| 39 | + :AnsiEsc -- toggles Ansi escape sequence highlighting |
| 40 | + :AnsiEsc! -- rebuilds highlighting for new/removed three |
| 41 | + or more element Ansi escape sequences. |
| 42 | + |
| 43 | + RESULT~ |
| 44 | + Ansi escape sequences become concealed or ignored (depending |
| 45 | + on whether your vim supports Negri's conceal mode), and their |
| 46 | + effect on subsequent text is emulated with Vim's syntax |
| 47 | + highlighting. |
| 48 | + |
| 49 | + Syntax highlighting for one and two element codes are |
| 50 | + hard-coded into AnsiEsc.vim. There are too many possibilities |
| 51 | + for three or more element codes; these are supported by |
| 52 | + examining the file for such sequences and only building syntax |
| 53 | + highlighting rules for such sequences as are actually present |
| 54 | + in the document. |
| 55 | + |
| 56 | + |
| 57 | + CUSTOMIZATION~ |
| 58 | + AnsiEsc does not know how to read what your terminal does with |
| 59 | + several escape sequences. One may customize what AnsiEsc does |
| 60 | + with these by specifying global variables which specify the |
| 61 | + desired highlighting: |
| 62 | + |
| 63 | + *g:ansiNone* use this variable to specify what should be done |
| 64 | + with <esc>[0m and <esc>[m. Example: > |
| 65 | + let g:ansiNone="hi gui=NONE cterm=NONE fg=white bg=black ctermfg=7" |
| 66 | +< |
| 67 | + *g:ansiBold* use this variable to specify what should be |
| 68 | + done with <esc>[1m |
| 69 | + |
| 70 | + *g:ansiItalic* use this variable to specify what should be |
| 71 | + done with <esc>[3m |
| 72 | + |
| 73 | + *g:ansiUnderline* use this variable to specify what should be |
| 74 | + done with <esc>[4m |
| 75 | + |
| 76 | + EXAMPLE~ |
| 77 | + |
| 78 | + You'll want to use :AnsiEsc to see the following properly! |
| 79 | + |
| 80 | + [34;47mColor Escape Sequences[m |
| 81 | +[37m - [m [37;1m 1 [m [37;2m 2 [m [37;3m 3 [m [37;4m 4 [m [37;5m 5 [m [37;7m 7 [m |
| 82 | +[30mblack[m [30;1mblack[m [30;2mblack[m [30;3mblack[m [30;4mblack[m [30;5mblack[m [30;7mblack[m |
| 83 | +[31mred[m [31;1mred[m [31;2mred[m [31;3mred[m [31;4mred[m [31;5mred[m [31;7mred[m |
| 84 | +[32mgreen[m [32;1mgreen[m [32;2mgreen[m [32;3mgreen[m [32;4mgreen[m [32;5mgreen[m [32;7mgreen[m |
| 85 | +[33myellow[m [33;1myellow[m [33;2myellow[m [33;3myellow[m [33;4myellow[m [33;5myellow[m [33;7myellow[m |
| 86 | +[34mblue[m [34;1mblue[m [34;2mblue[m [34;3mblue[m [34;4mblue[m [34;5mblue[m [34;7mblue[m |
| 87 | +[35mmagenta[m [35;1mmagenta[m [35;2mmagenta[m [35;3mmagenta[m [35;4mmagenta[m [35;5mmagenta[m [35;7mmagenta[m |
| 88 | +[36mcyan[m [36;1mcyan[m [36;2mcyan[m [36;3mcyan[m [36;4mcyan[m [36;5mcyan[m [36;7mcyan[m |
| 89 | +[37mwhite[m [37;1mwhite[m [37;2mwhite[m [37;3mwhite[m [37;4mwhite[m [37;5mwhite[m [37;7mwhite[m |
| 90 | + |
| 91 | +Black [30;40mB[m [30;41mB[m [30;42mB[m [30;43mB[m [30;44mB[m [30;45mB[m [30;46mB[m [30;47mB[m |
| 92 | +Red [31;40mR[m [31;41mR[m [31;42mR[m [31;43mR[m [31;44mR[m [31;45mR[m [31;46mR[m [31;47mR[m |
| 93 | +Green [32;40mG[m [32;41mG[m [32;42mG[m [32;43mG[m [32;44mG[m [32;45mG[m [32;46mG[m [32;47mG[m |
| 94 | +Yellow [33;40mY[m [33;41mY[m [33;42mY[m [33;43mY[m [33;44mY[m [33;45mY[m [33;46mY[m [33;47mY[m |
| 95 | +Blue [34;40mB[m [34;41mB[m [34;42mB[m [34;43mB[m [34;44mB[m [34;45mB[m [34;46mB[m [34;47mB[m |
| 96 | +Magenta [35;40mM[m [35;41mM[m [35;42mM[m [35;43mM[m [35;44mM[m [35;45mM[m [35;46mM[m [35;47mM[m |
| 97 | +Cyan [36;40mC[m [36;41mC[m [36;42mC[m [36;43mC[m [36;44mC[m [36;45mC[m [36;46mC[m [36;47mC[m |
| 98 | +White [37;40mW[m [37;41mW[m [37;42mW[m [37;43mW[m [37;44mW[m [37;45mW[m [37;46mW[m [37;47mW[m |
| 99 | + |
| 100 | + Here's the vim logo: |
| 101 | + |
| 102 | + [30;48;5;22m/ \[m |
| 103 | + [30;48;5;22m/ \[m |
| 104 | + [30;48;5;22m/ \[m |
| 105 | + [30;48;5;22m/ \[m |
| 106 | + [38;5;34;48;5;251m+----+[30;48;5;22m [38;5;34;48;5;251m+----+[30;48;5;22m \[m |
| 107 | + [38;5;34;48;5;251m++ ++[30;48;5;22m [38;5;34;48;5;251m+- |[30;48;5;22m \[m |
| 108 | + [30;48;5;22m/[38;5;34;48;5;251m| |[30;48;5;22m [m[38;5;34;48;5;251m/ /[30;48;5;22m \[m |
| 109 | +[30;48;5;22mX [38;5;34;48;5;251m| |[30;48;5;22m [38;5;34;48;5;251m/ /O[30;48;5;22m \[m |
| 110 | + [30;48;5;22m\[38;5;34;48;5;251m| |[30;48;5;22m [38;5;34;48;5;251m/ /+-+[30;48;5;22m [38;5;34;48;5;251m+-\[30;48;5;22m/[38;5;34;48;5;251m/-+[m |
| 111 | + [38;5;34;48;5;251m| |/ /[30;48;5;22m [38;5;34;48;5;251m| |[30;48;5;22m [38;5;34;48;5;251m| v |[m |
| 112 | + [38;5;34;48;5;251m| / /[30;48;5;22m [38;5;34;48;5;251m| |[30;48;5;22m [m[38;5;34;48;5;251m| + [38;5;34;48;5;251m+|[m |
| 113 | + [38;5;34;48;5;251m| /[30;48;5;22m [38;5;34;48;5;251m| |[30;48;5;22m/[38;5;34;48;5;251m| |[38;5;34;48;5;251m\/[m[38;5;34;48;5;251m||[m |
| 114 | + [38;5;34;48;5;251m+----[30;48;5;22m\ [38;5;34;48;5;251m+-+ [38;5;34;48;5;251m+-+[m [38;5;34;48;5;251m++[m |
| 115 | + [30;48;5;22m\ /[m |
| 116 | + [30;48;5;22m\ /[m |
| 117 | + |
| 118 | + PROBLEM WITH EMBEDDING: |
| 119 | + |
| 120 | + AnsiEsc plugin highlighting cannot be embedded in another |
| 121 | + syntax language. |
| 122 | + |
| 123 | + AnsiEsc uses the syntax highlighting engine, so it is |
| 124 | + effectively another syntax highlighting language. But, |
| 125 | + there are major differences: |
| 126 | + |
| 127 | + * It supports being turned on and off |
| 128 | + |
| 129 | + * AnsiEsc is not a syntax highlighting file, it |
| 130 | + is a plugin |
| 131 | + |
| 132 | + * AnsiEsc dynamically determines some syntax |
| 133 | + highlighting by analyzing what's needed in the |
| 134 | + current file. |
| 135 | + |
| 136 | + To do a syntax highlighting file would involve an inordinate |
| 137 | + quantity of permutations, resulting in a file that would take |
| 138 | + much time to load (about a half hour with only a partially |
| 139 | + complete set of permutations on my system). |
| 140 | + |
| 141 | + Normally to embed a syntax highlighting language in another |
| 142 | + would involve a pair of syntax highlighting commands such as: |
| 143 | + |
| 144 | + syn include @AnsiEsc |
| 145 | + syn region ... defines the region where AnsiEsc |
| 146 | + \ highlighting is to occur ... contains=@AnsiEsc |
| 147 | + |
| 148 | + placed in the other syntax file's definitions. That won't |
| 149 | + work with AnsiEc because, again, AnsiEsc is not a syntax |
| 150 | + highlighting file. |
| 151 | + |
| 152 | + |
| 153 | +============================================================================== |
| 154 | +3. AnsiEsc Method *AnsiEsc-Method* {{{1 |
| 155 | + |
| 156 | +Method 1: AnsiEsc implements syntax highlighting rules for highlighting the |
| 157 | +basic eight colors (black-red-green-yellow-blue-magenta-cyan-white, plus gray) |
| 158 | +atop the same basic eight colors, and rules for italic, bold, and underline. |
| 159 | +These comprise a fixed set of syntax highlighting rules. |
| 160 | + |
| 161 | +Method 2: Ansi escape codes may also represent a 6x6x6 color cube for an |
| 162 | +additional 216 colors, plus 25 grayscale colors. To handle these, AnsiEsc |
| 163 | +analyzes the file and builds custom syntax highlighting rules. These comprise |
| 164 | +a variable set of syntax highlighting rules. I did it this way because things |
| 165 | + |
| 166 | + a) broke (ie. vim was unable to handle 262000+ syntax highlighting rules), |
| 167 | + and |
| 168 | + |
| 169 | + b) took excessive amounts of time to load a fixed set of rules for |
| 170 | + 256 foreground atop 256 background syntax highlighting rules with |
| 171 | + variants for italic, underline, and bold. |
| 172 | + |
| 173 | + |
| 174 | +============================================================================== |
| 175 | +4. AnsiEsc History *AnsiEsc-history* {{{1 |
| 176 | + v13 Apr 12, 2012 * (Peter Brant) a "conceal" was left on a syntax |
| 177 | + definition in a no-conceal-support if block. |
| 178 | + Fixed. |
| 179 | + Apr 17, 2012 * (Ingo Karkat) support for the "reverse" attribute |
| 180 | + May 13, 2014 * (Jason Schmidt) reported that <esc>[39m didn't work. |
| 181 | + This means revert to default foreground. Similarly, |
| 182 | + <esc>[49m didn't work (which means revert to default |
| 183 | + background). |
| 184 | + Dec 11, 2014 * Implemented implicit foreground/background |
| 185 | + Jan 10, 2015 * (Evgeny Lukianchikov) provided XUbuntu support for |
| 186 | + no-ansi-sequence (AnsiNone) |
| 187 | + Sep 06, 2016 * Implemented bold/italic/underline without color |
| 188 | + specification |
| 189 | + Feb 18, 2017 * ansiConceal priority overruled foregroup specs |
| 190 | + containing background specs. |
| 191 | + (reported by Lucas Hoffman) |
| 192 | + Apr 10, 2018 * (James McCoy) provided a patch so that the |
| 193 | + |'highlight'| option is no longer used when |
| 194 | + conceal is available (see |'conceallevel'|) |
| 195 | + May 01, 2019 * (barrie) reported that <esc>[24m was showing up as |
| 196 | + a "stray m". Reason: ansiSuppress wasn't handling |
| 197 | + the code. |
| 198 | + Jul 21, 2020 * (Sergey Vlasov) reported that bold text atop |
| 199 | + variously colored backgrounds wasn't being |
| 200 | + highlighted. |
| 201 | + v12 Jul 23, 2010 * changed conc to |'cole'| to correspond to vim 7.3's |
| 202 | + change |
| 203 | + * for menus, &go =~# used to insure correct case |
| 204 | + Aug 10, 2010 * (Rainer M Schmid) changed conceallevel setting to |
| 205 | + depend on whether the version is before vim 7.3; |
| 206 | + for 7.3, also sets concealcursor |
| 207 | + * Restores conc/cole/cocu settings when AnsiEsc is |
| 208 | + toggled off. |
| 209 | + Dec 13, 2010 * Included some additional sequences involving 0 |
| 210 | + Feb 22, 2011 * for menus, &go =~# used to insure correct case |
| 211 | + v11 Apr 20, 2010 * AnsiEsc now supports enabling/disabling via a menu |
| 212 | + * <esc>[K and <esc>[00m now supported (as |
| 213 | + grep --color=always issues them) |
| 214 | + v10 May 06, 2009 * Three or more codes in an ANSI escape sequence are |
| 215 | + supported by building custom syntax and highlighting |
| 216 | + commands. |
| 217 | + May 20, 2009 * cecutil bugfix |
| 218 | + v9 May 12, 2008 * Now in plugin + autoload format. Provides :AnsiEsc |
| 219 | + command to toggle Ansi-escape sequence processing. |
| 220 | + Jan 01, 2009 * Applies Ignore highlighting to extended Ansi escape |
| 221 | + sequences support 256-colors. |
| 222 | + Mar 18, 2009 * Includes "rapid blink" ansi escape sequences. Vim |
| 223 | + doesn't have a blinking attribute, so such text uses |
| 224 | + "standout" for vim and "undercurl" for gvim. |
| 225 | + v8 Aug 16, 2006 * Uses undercurl, and so is only available for vim 7.0 |
| 226 | + v7 Dec 14, 2004 * Works better with vim2ansi output and Vince Negri's |
| 227 | + conceal patch for vim 6.x. |
| 228 | + v2 Nov 24, 2004 * This version didn't use Vince Negri's conceal patch |
| 229 | + (used Ignore highlighting) |
| 230 | + |
| 231 | +============================================================================== |
| 232 | +Modelines: {{{1 |
| 233 | +vim:tw=78:ts=8:ft=help:fdm=marker: |
0 commit comments