0

I'm using ruby-test to run rails tests from inside emacs into the *Ruby-Test* buffer. It works great except that the output is cluttered with ascii color-control characters (not sure what the right terminology is).

Example:

MyTest:
    ^[[32m     PASS^[[0m Test Passed (2.85s) 

If I run the test in a terminal that shows up as a green "PASS". Is there something I can do to get the colors to show up in my output buffer?

There's a related question about getting color for commands run with M-|, but I couldn't figure out how to adapt it for a generic buffer.

emacs shell command output not showing ANSI colors but the code

Community
  • 1
  • 1
spike
  • 9,794
  • 9
  • 54
  • 85

3 Answers3

1

In order to get Emacs to guess ansi-color mode for regular buffers, use:

(require 'tty-format)
(add-hook 'find-file-hooks 'tty-format-guess)

You need to download the tty-format package first. See: https://unix.stackexchange.com/questions/19494/how-to-colorize-text-in-emacs

Looking at the code, it looks like the author's made a bunch of questionable decisions, but maybe this will help:

(defadvice ruby-test-runner-sentinel (after add-ansi-colors activate compile)
  (ansi-color-apply-on-region (point-min) (point-max)))
Community
  • 1
  • 1
event_jr
  • 17,467
  • 4
  • 47
  • 62
  • This is promising, but it didn't work completely. I now get colors if I save the output of the *Ruby-Test* buffer to a text file and then open that file, but just going to the buffer doesn't show the colors (even if I force text-mode). Also I can use the ansi-color-apply-on-region-int function defined in your link manually on the region, but how do I make it automatic? – spike Sep 29 '11 at 03:38
  • I added a defadvice which may help. A word of warning: a lot of the stuff I see in this package make me want to look for alternatives if I were about to use it. – event_jr Sep 29 '11 at 04:16
  • No luck with that, maybe because the invoke-test-file function completes before the output of the test is piped back to the buffer? – spike Sep 29 '11 at 16:02
  • you're right. advice the sentinel instead then. see my modified answer. – event_jr Sep 29 '11 at 16:15
  • Unfortunately I'd preemptively tried that to no avail. Could you explain what add-ansi-colors is doing? I can't find it in any help. I also tried removing the filename regex tests in tty-format-guess. – spike Sep 29 '11 at 16:35
  • ok isee tty-format-guess is the wrong thing to call. Maybe call my ansi-color-apply-on-region then. see my modification. – event_jr Sep 29 '11 at 16:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/3903/discussion-between-event-jr-and-spike) – event_jr Sep 29 '11 at 16:52
0

Do you have ansi-color.el installed and active? See this also.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
0

Try running the

ansi-color-for-coming-mode-on

function in this buffer

Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94
  • I tried this (ansi-color-for-comint-mode-on) but it didn't work. The docs state that it only affects "shell buffers". Do you know what that means? – spike Sep 28 '11 at 22:11