GithubHelp home page GithubHelp logo

Some colours are grey about crayon HOT 10 CLOSED

r-lib avatar r-lib commented on June 12, 2024
Some colours are grey

from crayon.

Comments (10)

richfitz avatar richfitz commented on June 12, 2024

Beautiful, thanks!

from crayon.

richfitz avatar richfitz commented on June 12, 2024

This is a problem again, at least on my system (linux, terminal, R 3.2.2 with github and CRAN versions of crayon). Can you reopen? Any idea how to detect regressions?

from crayon.

richfitz avatar richfitz commented on June 12, 2024

crayon

from crayon.

gaborcsardi avatar gaborcsardi commented on June 12, 2024

I am not sure if this is a regression. But it could be. What does crayon::num_colors() say? Sys.getenv()? (Remove authentication tokens!)

from crayon.

richfitz avatar richfitz commented on June 12, 2024

You're right, sorry for the false alarm -- my OSX system displays the colour correctly (reporting 256 for num_colors()) while Linux is reporting 8 colours.

That's coming from system("tput colors") reporting 8 colours, even though this is definitely not an 8 colour terminal.

Forcing the terminal type by running

TERM=xterm-256color tput colors

gives the right number. Likewise,

TERM=xterm-256color Rscript -e 'message(crayon::make_style("hotpink")("asdfa"))'

prints the pink correctly. So while this is definitely a configuration issue, this suggests that this 8 colour reporting/256 colour capability configuration is typical. This SO answer might provide a less stringent test, as it seems likely that 256 colour support will be more common than 8 colour support this century 😄

from crayon.

gaborcsardi avatar gaborcsardi commented on June 12, 2024

Thanks for the links. The thing is, the method suggested in the SO answer does not work for me on OSX, in iterm. :/ I think if you know that your terminal supports 256 colors, you can just set TERM accordingly. This is the simplest solution, and I suspect that it is the only safe one that works on all platforms.

from crayon.

richfitz avatar richfitz commented on June 12, 2024

What would happen if rather than getting the result of tput just assuming 256? Is there even an 8 colour terminal easily available to see how it looks? Being able to rely in >8 colours makes using the package a lot easier (otherwise all end users will have to set TERM, even if it's several dependencies deep). I can dig around and see what the node packages for this do if that's useful. Or you can keep the current behaviour, which I agree is probably safest.

from crayon.

gaborcsardi avatar gaborcsardi commented on June 12, 2024

What would happen if rather than getting the result of tput just assuming 256?

I have no idea.

Is there even an 8 colour terminal easily available to see how it looks?

Emacs is surely 8 color.

Being able to rely in >8 colours makes using the package a lot easier (otherwise all end users will have to set TERM, even if it's several dependencies deep).

I can default to 256 if TERM is xterm. I guess this solves most issues. But then I need a mechanism to fall back to 8 colors.

I can dig around and see what the node packages for this do if that's useful.

This is what the most popular node package does: https://github.com/chalk/supports-color/blob/master/index.js

So how about defaulting to 256 if TERM is xterm?

from crayon.

richfitz avatar richfitz commented on June 12, 2024

In emacs, when forcing 256 colours with:

crayon::make_style("hotpink", colors=256)

I get unstyled output, which doesn't seem too tragic a failing.

Looks like node is going with 8 colours with xterm. And apparently setting TERM is liable to cause unspecified things. What a mess.

from crayon.

gaborcsardi avatar gaborcsardi commented on June 12, 2024

Please reopen if you have issues.

from crayon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.