11

This is related to this question : How to get coloured file listing in windows cmd shell ?

I'm trying to get, wouldn't you believe it, coloured file listing in windows cmd shell. Windows are XP SP2, if that matters.
In the old DOS days there used to be little programs like hdir, adir and such which displayed that nice. Nowadays, such programs are no more.

There is however, ls, from unixkit-tiny or unixtools. Unfortunatelly, it uses ANSI escape codes for displaying colours, and cmd doesn't handle those too well.

There are several solutions which include loading ansi.sys and command.com, but command.com doesn't handle long filenames that well, and is awfully slow. Even then sometimes it has problems displaying colours.

So what I'm asking, is there a way to get coloured file listing in windows cmd shell, apart from using cygwin ? Or is there a way to get ANSI escape codes to work with cmd.exe in a way so that native ls will play nicely ?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Rook
  • 60,248
  • 49
  • 165
  • 242

4 Answers4

16

I ran across ANSICON at http://adoxa.110mb.com/ansicon/index.html ansicon github repo

Using it to colorize NAnt output. ls --color is being processed correctly.

Source code is provided, but I haven't examined it.

David
  • 9,635
  • 5
  • 62
  • 68
Peter
  • 176
  • 1
  • 3
  • And the +A award deservedly goes to ... :) – Rook Nov 18 '09 at 21:30
  • This works quite nicely - tried it with 'wirble' for Ruby 'irb': http://www.rubyinside.com/wirble-tab-completion-and-syntax-coloring-for-irb-336.html#respond – monojohnny Jan 13 '10 at 11:31
  • 2
    WARNING: When installed as a CMD autostart entry ansicon might break things in unexpected ways! I wasted hours tracking down a freeze with a gui app (Eclipse) and found ascicon to be the culprit. Apparently, it restarts `cmd.exe` and that does not go well with some apps. Otherwise it does its job well if launched manually. The problem does not seem to be strictly related to ansicon - I had 'doskey' as an autostart cmd entry and it also created problems, specifically with gui apps which launch external console utils in the background, with or without creating a console. – ccpizza Feb 05 '12 at 18:37
  • 2
    Great tip! run "ansicon -i" to install into registry of Win7... now I have beautiful color! – JoshuaDavid Jun 21 '12 at 04:07
4

Actually I reckon A+ for ansicon -- Use

  • ansicon.exe -I

Installs it as a filter on your CMD.exe sessions. Works a treat with HTTY (ruby gem).

:-)

will
  • 4,799
  • 8
  • 54
  • 90
2

You could start the builtin Telnet server, firewall it to only allow localhost access, and use a telnet client that understands such escapes - even the native one. (I know, an ugly hack.)

user1686
  • 13,155
  • 2
  • 35
  • 54
1

It's possible to patch cmd.exe....

http://gynvael.coldwind.pl/?id=130&lang=en

Andrew Grant
  • 58,260
  • 22
  • 130
  • 143