views:

541

answers:

6

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.

A: 

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
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.
+1  A: 

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
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.
+1  A: 

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.

andras
that's a really, really good idea. I haven't though of approaching from this direction. I will look into this on Monday.
SF.
It appears PabloDraw does exactly what I need. The "multiplayer" feature is a nice bonus, allows for cooperative dump analysis.
SF.
I bet the authors didn't even remotely considered this usage scenario when they developed it. :-)
andras
+1  A: 

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
A: 

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
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
+2  A: 

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
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