ANSI escape sequences color rendering
-
Hello,
That feature request has actually been pretty well formulated in that thread (2018):
https://community.notepad-plus-plus.org/topic/16612/interprete-ansi-color…but it has been locked since and never received any reply.
Is it not relevant ? (why ?)
It’s quite handy to capture a color-formatted stream out of a log handler into a file, and of course to be able to visualize it with rendering as it would be in a regular console (with type, more, less, etc.)
…Notepad even offers “tail -f” as a real-time log tracer : wouldn’t it be natural to offer ANSI escape sequences colors (rather than the awful actual codes as in “[1;33m This is a warning [0m”)Thanks
Xavier -
It was locked simply because it was old and inactive. As to why no one answered then, I don’t know.
Notepad++ is a text editor, and those codes and the colors they produce in ANSI.sys environments are not text, they are binary sequences. Notepad++ does the best it can and renders those codes as if they were text characters.
Someone could write a plugin that would take the raw source code and render it in a separate panel, like the Markdown++ or HTML Preview plugins do. But there are a lot of ANSI escape sequences besides colors, and not all make sense in a text editor.
-
I had another idea: the EnhanceAnyLexer plugin allows you to use regular expressions (regex) to add foreground coloring to any lexer (whether builtin or a User Defined Language). (The plugin isn’t (yet) in the Plugins Admin list, so you have to manually install it from the github I linked.)
If you have the text
Initial text [30mSomeTextGoeshere[0mOther Text Goes Here Initial text [31mSomeTextGoeshere[0mOther Text Goes Here Initial text [32mSomeTextGoeshere[0mOther Text Goes Here Initial text [33mSomeTextGoeshere[0mOther Text Goes Here Initial text [34mSomeTextGoeshere[0mOther Text Goes Here Initial text [35mSomeTextGoeshere[0mOther Text Goes Here Initial text [36mSomeTextGoeshere[0mOther Text Goes Here Initial text [37mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;30mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;31mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;32mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;33mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;34mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;35mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;36mSomeTextGoeshere[0mOther Text Goes Here Initial text [1;37mSomeTextGoeshere[0mOther Text Goes Here
You can set up an empty UDL called
ANSIEscape
, and then add the following to the EnhanceAnyLexerConfig.ini:[ANSIEscape] ; For Control Sequence Introducer, or CSI, commands, the ESC [ is followed by any number (including none) of "parameter bytes" in the range 0x30–0x3F (ASCII 0–9:;<=>?), then by any number of "intermediate bytes" in the range 0x20–0x2F (ASCII space and !"#$%&'()*+,-./), then finally by a single "final byte" in the range 0x40–0x7E (ASCII @A–Z[\]^_`a–z{|}~). 0x808080 = \x1B\x5B[0-?]*[!-/]*[@-~] 0x000000 = (\x1B\x5B(\d+;)?30m)\K(.*?)(?=\x1B\x5B0m) 0x0000C0 = (\x1B\x5B(\d+;)?31m)\K(.*?)(?=\x1B\x5B0m) 0x00C000 = (\x1B\x5B(\d+;)?32m)\K(.*?)(?=\x1B\x5B0m) 0x00C0C0 = (\x1B\x5B(\d+;)?33m)\K(.*?)(?=\x1B\x5B0m) 0xC00000 = (\x1B\x5B(\d+;)?34m)\K(.*?)(?=\x1B\x5B0m) 0xC000C0 = (\x1B\x5B(\d+;)?35m)\K(.*?)(?=\x1B\x5B0m) 0xC0C000 = (\x1B\x5B(\d+;)?36m)\K(.*?)(?=\x1B\x5B0m) 0xC0C0C0 = (\x1B\x5B(\d+;)?37m)\K(.*?)(?=\x1B\x5B0m)
Then it will format as per the following screenshot:
The EnhanceAnyLexer plugin won’t be able to affect background, or bold/italic/underline, but it can at least do the foreground color. (And obviously, this won’t handle position/etc… but I wouldn’t want it to while editing the source code for the ANSI-escaped document) If you want the 256-color variant, you would have to program another 256 regexes to handle it… I thought showing just the default 8 colors would be sufficient for demonstration purposes.
In theory, with a similar block in the INI file, you would be able to set up the same rules for the MS-DOS Style builtin lexer, but it’s got a confusing name (
MS-DOS Style
in Language menu,Dos Style
in Style Configurator, andMSDOS Style/ASCII Art
in the status bar), and I couldn’t figure out the name to use in the[...]
header–
-
Were you planning on adding EnhanceAnyLexer to NppPluginList, so that we can direct people to Plugins Admin rather than making them manually install it?
-
For the multi-word named languages, like
Fortran (free form)
, I think I found that it matches the prefix in the status bar (soFortran free form
). If that’s right, it should be made clear in the default .ini file that the group name must match the status-bar-text, not the name in the Language menu or Style Configurator.
When I tried that rule for the MS-DOS group name, with[MSDOS Style/ASCII Art]
, that would not style it (nor would using names any of the three listed in the paragraph above)… but I don’t know if that’s just because the MS-DOS lexer does extra overrides on styling to change the font and encoding as well, and thus it overrides your plugin, or whether it’s because the status-bar-text-name has the/
in it, which maybe confuses something in your INI parser. But unless it’s something that the MSDOS-lexer is doing to prevent your plugin from styling, it should probably be made to actually work with any of the builtin lexers
-
-
@peterjones said in ANSI escape sequences color rendering:
Were you planning on adding EnhanceAnyLexer to NppPluginList, so that we can direct people to Plugins Admin rather than making them manually install it?
Yes, but I have not yet checked what needs to be done to make this work with v lang and gcc.
To do the tests, I am hesitant to install visual studio to get a debug version, but I couldn’t get gcc to build either. Hmm …For the multi-word named languages, like Fortran (free form), I
You are right, basically I am asking Npp with nppm_getlanguagename for the programming language currently in use. I will make this clearer, thanks for the suggestion.
By the way, there is an error_list lexer script for this particular problem and an 8.4 compatible version along with a FR that asks for an option to disable non-styling of larger text files. @Xavier-Beaume
-
@ekopalypse said in ANSI escape sequences color rendering:
You are right, basically I am asking Npp with nppm_getlanguagename for the programming language currently in use
Which, for a language called MS-DOS Style or a variant thereof everywhere else will “obviously” be “NFO” as the result from that call. Sheesh: Four different names for the same Language, depending one where you look!
And yes, using
[NFO]
as the group name in the INI file will result in the MS-DOS Style language accepting EnhanceAnyLexer formatting.Thanks.
—
For future reference: The source-code for each of the four strings can be found in the repo:
Text Source Notes MS-DOS Style
Notepad_plus.rc#L929 & #L1054 Translated via id="46015"
, for example in esperanto.xml, though not all translations (including english.xml) provide that IDDos Style
theme.xml In many themes as <LexerType name="nfo" desc="Dos Style" ext="">
, though langs.model.xml does not have thedesc
attributeMSDOS Style/ASCII Art
ScintillaEditView.cpp#L82 _longName column NFO
ScintillaEditView.cpp#L82 _shortName column -
I wanted to add something like this
; Each configured lexer must have a section with its name, ; which can be seen in the first field of the status bar, ; followed by one or more lines with the syntax ; color = regular expression.
Does that make sense?
-
updated version
; Each configured lexer must have a section with its name, ; which can be seen in the first field of the status bar, ; (and in the case of a UDL, use only the part after "User defined language file - ") ; followed by one or more lines with the syntax ; color = regular expression.
-
Looks good.
-
-