47

I need some tool to display text containing ANSI codes correctly on Windows. No full support needed, but at least coloring/bold is a must.

Reason: My logger/debug module produce nicely rendered rich output with important sections colored using ANSI codes. This helps a lot when debugging on the serial terminal, but if I dump the debug to a file or copy-paste it into a text editor on Windows (interactive remote debug is not always viable), at best all the ANSI codes are stripped, at worst they are rendered as junk characters obscuring the real data. Rudimentary editing capabilities would be appreciated to be able to pick out specific parts, annotate, and so on.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
SF.
  • 13,549
  • 14
  • 71
  • 107

11 Answers11

14

The open-source editor Atom has the package language-ansi-styles. It supports all kinds of formatting except ;r;g;b.

enter image description here enter image description here

guo
  • 195
  • 1
  • 2
  • 12
11

You might have some more luck with ASCII/ANSI utilities, like the ones listed here: List of ASCII/ANSI/NFO utilities

**Note: some files on this page might be outdated, you might find newer versions of these utilities on their respective homepages.*

For example, the latest version of NFOPad can be found here.

Community
  • 1
  • 1
Andras Vass
  • 11,478
  • 1
  • 37
  • 49
  • that's a really, really good idea. I haven't though of approaching from this direction. I will look into this on Monday. – SF. Feb 21 '10 at 12:12
  • 3
    It appears PabloDraw does exactly what I need. The "multiplayer" feature is a nice bonus, allows for cooperative dump analysis. – SF. Feb 25 '10 at 11:57
  • 1
    I bet the authors didn't even remotely considered this usage scenario when they developed it. :-) – Andras Vass Feb 25 '10 at 12:43
  • @SF What version are you using? Does it interpret tabs correctly? Mine is showing tiny circles instead of actually indenting the text. – Malabarba Sep 14 '11 at 00:34
  • @Bruce: In my logs and debugs I don't use tabs so that was never a problem for me. – SF. Sep 14 '11 at 07:44
10

I've been looking for a solution to display the ANSI colors as well (for program debug output readability) and stumbled upon Sublime Text (paid software with trial http://www.sublimetext.com/) with a the ANSIescape package (https://github.com/aziz/SublimeANSI or installed through the package control).

It supports coloring and the bold escape is recognized but not displayed, although a special color can be assigned to it in the settings file. Also worth noting that this plugin shows text in read-only mode, and needs to be turned off if editing is necessary.

Here is the screenshot provided on the github, and I have personally tried it and verified it works:

enter image description here

autronix
  • 2,885
  • 2
  • 22
  • 28
  • I downloaded sublime text and then downloaded the package zip file and copied it into the sublime packages folder and re-named it to `ANSIescape` - as per the instructions in the readme for the plugin. But I don't see any syntax called "ANSI" looking under view -> syntax. Can you tell me how you managed to get it working? thanks! – code_fodder Mar 19 '20 at 19:10
8

If you're primarily interested in viewing the file instead of editing it, Ansifilter will convert it to HTML, which you can then view and at least search in your browser, or RTF if wordpad would be good enough (hard to imagine). Huh, looks like there's a notepad++ plugin version on the download page, too, so that might be perfect if it allows you to load into notepad++.
http://www.andre-simon.de/doku/ansifilter/ansifilter.html

There's also a different plugin for vim which colors text according to ANSI codes.
http://www.vim.org/scripts/script.php?script_id=302

However, while it highlights the text in the correct color, it leaves the ANSI codes themselves in there (in a faded, near-background color) which probably will mess up any alignment formatting in the file, as well as making it harder to move around the file (lots of "empty space" to wade the cursor through, searching for a word won't match if there's an ansi code in the middle of it, etc.). There's a patch it can take advantage of to hide the codes too, but that would require patching and then recompiling vim itself from source.

Yeah, suggesting vim is pretty unhelpful if you aren't a vim user already, it has too huge of a learning curve, I know. But it might be useful to the vim users out there.

Jeffson
  • 581
  • 3
  • 3
  • 2
    Just an update on this: the "conceal" patch requested by the Vim script you mentioned is now part of Vim as of version 7.3. In other words, Vim is now able to display colored Ansi text. – UncleZeiv Oct 14 '10 at 10:26
  • Ansifilter is especially useful; I wrote a wrapper to grab colored text, generate tex from ansifilter, compile it and launch the viewer which is super handy as a custom command added in git. – kabZX Dec 09 '15 at 13:55
  • 1
    I know this is a very old answer, but it seems that the Notepad++ plugin for AnsiFilter doesn't exist anymore. – Fabio says Reinstate Monica May 16 '19 at 10:32
  • @FabiosaysReinstateMonica yeah, I was looking for that... not there :(( - did you find anything else? – code_fodder Mar 19 '20 at 20:16
  • 2
    @code_fodder I've just had another look, and found this: https://sourceforge.net/p/npp-plugins/discussion/667712/thread/33551030/ But I haven't tried it, and I expect it's for the old ANSI version of N++ (unrelated to the "Ansi" of "AnsiFilter"). The current version of N++ is Unicode, and plugins are incompatible, they must be recompiled before they can be run. And that .zip doesn't contain the source, so I think the project is dead, and I won't look any further. Sorry! – Fabio says Reinstate Monica Mar 20 '20 at 03:28
  • @FabiosaysReinstateMonica oh shame, thanks for the update Fabio : ) – code_fodder Mar 20 '20 at 09:59
  • Check out: https://chrome.google.com/webstore/detail/retrotxt/gkjkgilckngllkopkogcaiojfajanahn Works quite well! Set it to XTerm and it looks just like normal logs – Anthony Apr 03 '23 at 01:58
3

I know it won't be of much help - but I was looking for the exact same thing on linux; was just trying to view some log outputs that had bash ANSI color codes inside. Unfortunately, those ANSI color codes were spread across several lines - meaning 'cat'-ing the file and piping into 'less -R', 'most' and similar tools, would simply display the starting line where the color originated, but not the subsequent lines that should've been colored.

Funnily enough, I thought usual Linux tools like 'nano', 'gedit', 'vim' and whatnot would have capabilities for ANSI color codes in a text file, but it's very modest out there with info on ANSI color in text files in these editors. I've only found info on ANSI color for the test editor 'joe':

Cheap ANSI Color! - http://tldp.org/LDP/LG/issue01to08/articles.html#ansi

but couldn't get the recommendations there to work (also couldn't get 'emacs' to work either, at least not by directly reading a text file with ANSI color characters inside).

The good thing - it seems what you need, if you need ANSI color in text, is to look for ASCII art / NFO utilities as recommended above - and the one that I finally found, and was working for me, was tetradraw (via www.linux.org/apps/AppId_42.html ; can be sudo apt-get installed in Ubuntu ... actually, tetradraw is the name of the drawing/editor part - however there is a separate viewer that also works with ANSI color codes, tetraview).

Well, who would have thought, that you need to track down an ASCII art utility, in order to read log files :)

Anyways, hope this may somehow help in the further search of ANSI color text editors for Windows, too.. Cheers!

sdaau
  • 36,975
  • 46
  • 198
  • 278
2

If you just want to view then the terminal program "Tera Term" can do this. Just click "File" -> "Replay Log" and select your file containing the ANSI codes.

You can download Tera Term here: http://logmett.com/index.php?/download/tera-term-477-freeware.html

Trevor
  • 21
  • 2
2

In Emacs, just eval the following before opening your .nfo file:

(add-to-list 'auto-coding-alist '("\\.nfo\\'" . cp437-dos))

ens
  • 1,068
  • 13
  • 14
1

I have been a while testing multiple programs on the URL refered by Andras Vass with no results (they don't show colors, or they keep showing ANSI codes as a mess of characters).

Tired of searching I have finally found ANSIFilter (not the NotePad++ plugin refered by Jeffson), the only that works for me. I have added it to Windows context menu, so I can now easily open my ANSI text files.

Sopalajo de Arrierez
  • 3,543
  • 4
  • 34
  • 52
0

I would be surprised if emacs can't do that. At least with the embeded shell. There are:

Update: as it had been pointed, they are just term output colorizers. But if you can edit the shell buffer contents in emacs too, eg. cat file && colorize.

But wait a minute, I had just found these:

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
  • 1
    these all seems like colorizers for shell inside Emacs, not colorizers for random text file natively opened in Emacs. It will allow to render the codes if I open shell in Emacs, and then some dumb editor inside that shell, then the debug file inside that dumb editor. It's hopelessly convoluted that way. – SF. Feb 16 '10 at 12:32
0

If the debug logging of your application goes via 1 class/function, you could try to split the output so that:

  • ANSI-like logging is shown on the terminal/console
  • HTML-like logging is written to file

For your application all logging goes to this class, and this class splits the output to terminal/console and file.

Make a 'standard' in your logging class for specifying colors and boldness (e.g. predefined codes like Ctrl-A means red, Ctrl-B means bold, ..., or specific methods in the logging class for setting the color and boldness, or maybe even the ANSI-codes), and translate this in your central logging class to:

  • the correct ANSI codes on terminal
  • the correct HTML codes in file

Alternatively, I think that instead of HTML you also could use rich-text, but I don't know all the possibilities of rich text so you may have to look this up.

Patrick
  • 23,217
  • 12
  • 67
  • 130
  • Note that in the long term you will benefit from this if you also want to support other kinds of logging outputs that have totally different formatting possibilities, or not formatting possibilities at all (e.g. database, ...). – Patrick Feb 21 '10 at 22:18
-5

You could try notepad++ (see http://notepad-plus.sourceforge.net/uk/site.htm). It's pretty powerful (Scintilla based) and has an option to view non-printable characters (like line-breaks and the like).

aefxx
  • 24,835
  • 6
  • 45
  • 55
  • 8
    Unfortunately Notepad++ appears to be displaying the escape sequences verbatim instead of interpreting/rendering them. I see `ESC`[1m Errror `ESC`[0m instead of seeing "Error" printed in bold. – SF. Feb 16 '10 at 10:35