Mocha: Allow custom color scheme

Created on 25 Sep 2012  路  25Comments  路  Source: mochajs/mocha

It should be possible to override the default color scheme defined in lib/reporters/base.js

The comment for the color function says this is possible:

/**
 * Color `str` with the given `type`,
 * allowing colors to be disabled,
 * as well as user-defined color
 * schemes.
 *
 */

var color = exports.color = function(type, str) {
  if (!exports.useColors) return str;
  return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
};

, but I haven't found a way to override the default colors (The types that are displayed in 90 are invisible on the Solarized Dark terminal theme).

All 25 comments

yeah it's not actually easy right now especially using mocha(1)

I too am having this issue, wrt the Solarized color scheme. For now I just turn colors off using -C

I'm also using the Solarized color scheme and got bitten by this issue. Doing the same thing to turn off colors with -C for now. Is there anything I can do to help get this resolved quicker?

tweak them so they're not invisible? :p it doesn't really make sense for any theme to show any of them as invisible that's asking for trouble

Seriously? I practically asked if I could fix it for you. I'm still digging into where exactly the theme is conflicting with Mocha's color commands, but given the fact that Solarized works with virtually every other command line utility I've run, I'm afraid that changing a setting with the theme would mess things up elsewhere.

I understand that it's not high priority, but it would be nice if there were a solution other than dismissing the issue as user error.

The theme isn't making it "invisible", the theme calculates a color that goes well with the theme from the original color. It just so happens that in this case, the color is very close to what the background is. There are many themes that do this, so it isn't uncommon. While it may not be a very high priority, I think it will be useful to allow overriding of colors (or other settings) using some sort of default override (similar to .noserc for python).

Overriding would be nice, it's an endless battle otherwise unless we just go with defaults for everything. I've seen this issue with component(1) and the person was using this Solarized theme and it was displaying gray as invisible, that's not my fault

see: https://github.com/component/component/issues/182
that's a theme error, you're either tweaking the theme, or you're tweaking _everything_ that uses those escape codes

Thanks for the update. I'll tweak my contrast settings. Would a settings override file be something you would pull?

maybe we'd be better off making some note of theme issues, not sure, I'm surprised this sort of thing isn't more common but I do use cyan and gray a lot so I kinda see how it's usually my stuff

The issue I'm having with mocha's color scheme isn't cyan<>gray, but "Bright Black" on "Background".

iTerm2's default dark:
n_ott0dai_oa

Tomorrow Night:
9kbvqftahyc1

Molokai:
 e84jpla6 j

Twilight:
usvhu8d6fgrp

Solarized just happens to make 'Bright Black' the same as the background color, so it's out-and-out invisible. If it's really a theme issue, it's a common one for dark themes.

One could argue the popularity statistics of the Solarized theme. My analysis would suggest that this theme is popular and has a lot of support and followers:

screen shot 2014-01-10 at 8 19 07 am

Regardless, one of the quickest ways to piss off other developers is to force your personal preferences on them. Difficulty set aside I think the real issue is that _if_ anyone were to make a Pull Request with the ability to customize colors would it even make it into the repository?

I'd also like to point out that you chose your terminal colors based on what you liked. If I reflect that back and offer a hypothetical: you make a Pull Request or issue to someone else's repository to help better support the colors you like and they flat out told you "No, your fault for picking those colors," how would you feel?

:+1: for entertaining customizing colors so themes like Solarized work.

I've come to expect that people use either black terminals or white terminals, and I as a developer can use any colors in between.

Is there any way to get a default background color? If there is, it can be fixed this way, otherwise it really seem like a theme issue.

https://github.com/visionmedia/mocha/issues/802 has the perfect fix for Mac on iTerm2 with solarized theme. Set the contrast up and all works perfect.

I can specify my git colors in ~/.gitconfig. Would be nice if there were something like that for Mocha.

Whether it's a terminal theme issue or not, it would be nice to have colors overridable. In mocha.opts perhaps ?

+1. on my black terminal I find the specific shade of red used for errors very hard to read and would like to be able to change it

incidentally, I changed the colour choices in lib/reporters/base.js but it didn't have any effect on the output so maybe there's some other location where this can be changed

it's a pity to have to turn colours off but how would I do it? my tests are run from a Gruntfile.js via mocha-phantomjs and I have an entry like this:

grunt.initConfig({
  mochaTest: {
    mocha_phantomjs: {
    all: ['tests/browser/*.html']
    }

@ekkis that's a question for whatever grunt plugin you're using, but the option in mocha is --no-colors

Still not fixed? I can't see mine at all, it's all black on black. :(

Several solutions for solarized have been proposed in #802 but rejected as "not my problem" by mocha developers. Support of customizing colors with a config file would not change the default but allow users to decide.

We could expend resources adding custom color support, OR the users with this problem could modify their terminal, which likely already has custom color support.

Solarized is a very common terminal theme and I'm sure this problem affects more than just the people on this thread.

The "not my problem" attitude alienates a community that wants to help out with maintenance and improvements. A little empathy goes a long way.

The "not my problem" attitude alienates a community that wants to help out with maintenance and improvements. A little empathy goes a long way.

I can't begin to tell you how profoundly mistaken you are. So I won't; instead, I'll lock this issue so I don't forget I shouldn't.

Was this page helpful?
0 / 5 - 0 ratings