Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print_with_color doesn't print with the correct colors #8096

Closed
ssfrr opened this issue Aug 22, 2014 · 7 comments
Closed

print_with_color doesn't print with the correct colors #8096

ssfrr opened this issue Aug 22, 2014 · 7 comments

Comments

@ssfrr
Copy link
Contributor

ssfrr commented Aug 22, 2014

Test code:

for color in [:red, :green, :blue]
    print_with_color(color, "Hello in $(color)\n")
end

When I put it in a script and run it I get all three in the default color. When I run it from the REPL I get an orangish, and 2 variations on my default color.

image

I'm guessing that it's using my terminal's color scheme, but it looks like it's possible to print green and red in my terminal, because FactCheck.jl is able to do it:

Here's the relevant FactCheck code:

const RED     = "\x1b[31m"
const GREEN   = "\x1b[32m"
const BOLD    = "\x1b[1m"
const DEFAULT = "\x1b[0m"

colored(s::String, color) = string(color, s, DEFAULT)
red(s::String)   = colored(s, RED)
green(s::String) = colored(s, GREEN)
bold(s::String)  = colored(s, BOLD) # Bold is a color. Shut up. [sic]
@ssfrr
Copy link
Contributor Author

ssfrr commented Aug 22, 2014

Ah, just found the --color option at the julia command line. With that I get the same output whether I'm running the script or at the REPL.

@ssfrr
Copy link
Contributor Author

ssfrr commented Aug 22, 2014

More digging, it looks like the reason is that FactCheck doesn't use the bold versions of the colors, but Julia's color codes do. In my color scheme (solarized), the bold versions of the colors are actually different colors.

This seems like perhaps more of an issue with the color scheme than Julia, as Julia can't expect to know what color scheme might be messing with the colors. I'll go ahead and close. Sorry for the noise.

@ssfrr ssfrr closed this as completed Aug 22, 2014
@floringogianu
Copy link
Contributor

@ssfrr I just noticed this same issue and reading on this I find it strange that the entire julia prompt forces bold fonts considering how difficult handling bold fonts appears to be.

@ssfrr
Copy link
Contributor Author

ssfrr commented Sep 21, 2014

Given the way the 16 ANSI colors are defined, it seems reasonable to assume that "bright red" would be a lot like "red", but "brighter". I've personally come to think that Solarized's use of the bright colors to be completely different colors, some of which are almost invisible on the background color, is a Bad Thing. Terminal color handling is confusing enough without changing around the meanings of colors, and the subtle combinations of terminal color schemes and application color schemes that are required to make Solarized work properly are to me an indication that it's more trouble than it's worth (though it is a pretty colorscheme).

I don't think that handling bold/bright colors needs to be that confusing unless colorscheme designers insist on abusing them.

@ssfrr
Copy link
Contributor Author

ssfrr commented Sep 21, 2014

Ranting aside though, given that we basically don't have any idea how the colors will show up on someone's screen, I don't see a reason to use the bold/bright versions of colors unless it's actually to contrast against the non-bold version. So it doesn't seem like it would hurt to stick with the non-bold versions in the REPL. I'm guessing this is @Keno's area?

@floringogianu
Copy link
Contributor

@ssfrr Yeah, the more I think about it I believe Julia should stick with the non-bold fonts...

IainNZ added a commit to JuliaAttic/FactCheck.jl that referenced this issue Oct 30, 2014
Apart from code reuse, this should work cross-platform.
Downside: you need to run tests with julia --color to get the coloured output
Upshot: Now more garbled escape codes in test logs on PkgEvaluator

@ssfrr I know you looked at this in JuliaLang/julia#8096,
so tagging you in case this interests you
@edljk
Copy link

edljk commented Nov 18, 2015

Is it possible to print text with genral colors defined in the package file Colors/src/names_data.jl ?
For instance

for color in [:red, :green, :blue, :magenta]
    print_with_color(color, "Hello in $(color)\n")
end

works well on my computer (linux, using zsh shell) whereas

print_with_color(:orange, "Hello \n")

prints Hello in a standard black color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants