Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

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

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!

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

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

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

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.

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:

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.

Notepad2 text editor claims to be a +"NFO"+ viewer.

/* Deleted Link */

edit: NFO not mentioned! I thought I saw it.

::

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top