Autotest, unit-diff, and color output?

I'm using autotest with all its test driven goodness, and I believe
that uses unit-diff to present a "saner" view of test difference
output.

I'd like to do colorize the output from unit-diff so its similar to
what you see on a changeset on trac, for instance. Does anyone know
anything that can colorize diffs in ruby, or know of a good starting
point? Or at least where to start for outputting color in the
terminal, so I can do "#{color.red} stuff" instead of using control
characters.

thanks,
Rob

···

--
http://www.robsanheim.com
http://www.seekingalpha.com
http://www.ajaxian.com

Rob Sanheim wrote:

I'm using autotest with all its test driven goodness, and I believe
that uses unit-diff to present a "saner" view of test difference
output.

I'd like to do colorize the output from unit-diff so its similar to
what you see on a changeset on trac, for instance. Does anyone know
anything that can colorize diffs in ruby, or know of a good starting
point? Or at least where to start for outputting color in the
terminal, so I can do "#{color.red} stuff" instead of using control
characters.

you can try facets' ansicode lib written primarily by Florian Frank.

t.

Rob Sanheim wrote:

I'm using autotest with all its test driven goodness, and I believe
that uses unit-diff to present a "saner" view of test difference
output.

I'd like to do colorize the output from unit-diff so its similar to
what you see on a changeset on trac, for instance. Does anyone know
anything that can colorize diffs in ruby, or know of a good starting
point? Or at least where to start for outputting color in the
terminal, so I can do "#{color.red} stuff" instead of using control
characters.

An easy, lightweight way to go would be to write a script that creates an
HTML file out of the diff data, popping in color-change tags as required,
using your own choice of colors and syntax rules. This would be very easy
to do, once you have decided how you want the output to look.

Of the available choices, HTML is actually very easy to exploit for a
formatting task like this.

Whoops, I just saw your having mentioned a terminal. Okay, then, you can use
ANSI colors instead, using a similar process, this time the script could be
a filter, the last step before displaying the data on the terminal. Same
syntax rules, different way to create the colors.

so I can do "#{color.red} stuff ...

Okay, here is an example:

···

-------------------------------------------------

#!/usr/bin/ruby -w

class ANSIColors

   ANSIColors::Col_hash = {
      :black => 30,
      :red => 31,
      :green => 32,
      :yellow => 33,
      :blue => 34,
      :magenta => 35,
      :cyan => 36,
      :white => 37
   }

   def ANSIColors::color(s)
      return "\033[#{Col_hash[s]}m"
   end
end

puts "#{ANSIColors::color(:red)} this should be red."

puts "#{ANSIColors::color(:green)} this should be green."

puts "#{ANSIColors::color(:blue)} this should be blue."

puts "#{ANSIColors::color(:black)} this should be black."

-------------------------------------------------

Try it on your terminal. If it doesn't work, chances are your terminal is
not ANSI-color enabled.

--
Paul Lutus
http://www.arachnoid.com

I'm using autotest with all its test driven goodness, and I believe
that uses unit-diff to present a "saner" view of test difference
output.

It does.

I'd like to do colorize the output from unit-diff so its similar to
what you see on a changeset on trac, for instance. Does anyone know
anything that can colorize diffs in ruby, or know of a good starting
point? Or at least where to start for outputting color in the
terminal, so I can do "#{color.red} stuff" instead of using control
characters.

The easiest way to do this is to write (or find) a color-capable diff executable. This way you don't have to change unit_diff, just your path.

···

On Dec 8, 2006, at 09:26 , Rob Sanheim wrote:

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!

Thanks for the responses everyone. Some quick google searches didn't
turn up any drop in color replacements for diff, though I did find it
as a feature request submitted for diff, but way to recently for any
code to be written yet.

- Rob

···

On 12/8/06, Eric Hodel <drbrain@segment7.net> wrote:

The easiest way to do this is to write (or find) a color-capable diff
executable. This way you don't have to change unit_diff, just your
path.

$ esearch colordiff
[ Results for search key : colordiff ]
[ Applications found : 1 ]

* app-misc/colordiff
      Latest version available: 1.0.5-r2
      Latest version installed: 1.0.5-r2
      Size of downloaded files: 41 kB
      Homepage: http://colordiff.sourceforge.net/
      Description: Colorizes output of diff
      License: GPL-2

martin

···

On 12/11/06, Rob Sanheim <rsanheim@gmail.com> wrote:

Thanks for the responses everyone. Some quick google searches didn't
turn up any drop in color replacements for diff, though I did find it
as a feature request submitted for diff, but way to recently for any
code to be written yet.

Thanks, apparently I should've searched on one word instead of "color diff". :slight_smile:

- rob

···

On 12/10/06, Martin DeMello <martindemello@gmail.com> wrote:

$ esearch colordiff
[ Results for search key : colordiff ]
[ Applications found : 1 ]

* app-misc/colordiff
      Latest version available: 1.0.5-r2
      Latest version installed: 1.0.5-r2
      Size of downloaded files: 41 kB
      Homepage: http://colordiff.sourceforge.net/
      Description: Colorizes output of diff
      License: GPL-2

martin

It's easier when you know it's there :slight_smile: I found it the first time by
searching for 'diff' in the portage tree

martin

···

On 12/11/06, Rob Sanheim <rsanheim@gmail.com> wrote:

On 12/10/06, Martin DeMello <martindemello@gmail.com> wrote:
> $ esearch colordiff
> [ Results for search key : colordiff ]
> [ Applications found : 1 ]

Thanks, apparently I should've searched on one word instead of "color diff". :slight_smile: