GithubHelp home page GithubHelp logo

windows shell support? about crayon HOT 20 CLOSED

r-lib avatar r-lib commented on June 1, 2024
windows shell support?

from crayon.

Comments (20)

gaborcsardi avatar gaborcsardi commented on June 1, 2024

Note that you can force-enable crayon with the crayon.enabled and the crayon.colors options, as a workaround.

Can we detect color support in powershell or with ansicont?

from crayon.

faridcher avatar faridcher commented on June 1, 2024

run powershell then rterm.exe and paste this:

cat("\033[32;1m OK \033[0m\n")

you will get colored output....

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

Yeah, but is there a way to detect this programmatically? How does R know that it is runnint in powershell, or in rterm with color support?

from crayon.

faridcher avatar faridcher commented on June 1, 2024

No idea! Is it important (it might be important if you want to show the user a meaningful message!)? the above line of code proves the support. If crayon does what it is supposed to do, then we should get colored output!

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

Crayon cannot emit color sequences, unless it knows that the platform supports it.

Again, if you just want to make it work for yourself, run this, maybe from your .Rprofile:

options(crayon.enabled = TRUE)
options(crayon.colors = 256)

from crayon.

wlandau-lilly avatar wlandau-lilly commented on June 1, 2024

What about enabling crayon in RStudio? I tried setting just options(crayon.enabled = TRUE) and then tried setting both options, but the color characters print out as text: "�[38;5;105m", "�[38;5;32m", etc. Should I try changing the encoding? I cannot find an encoding setting in RStudio's global options. For what it's worth, I also had a look at the README and #56.

from crayon.

wlandau-lilly avatar wlandau-lilly commented on June 1, 2024

I also submitted an SO post

from crayon.

wlandau-lilly avatar wlandau-lilly commented on June 1, 2024

Confirmed: the RStudio 1.1 preview supports crayon colors automatically. I had no idea.

from crayon.

sthupakula-rms avatar sthupakula-rms commented on June 1, 2024

What about enabling crayon in RStudio? I tried setting just options(crayon.enabled = TRUE) and then tried setting both options, but the color characters print out as text: "�[38;5;105m", "�[38;5;32m", etc. Should I try changing the encoding? I cannot find an encoding setting in RStudio's global options. For what it's worth, I also had a look at the README and #56.

It's an old post, but did you find a fix for this? I still can't get colors on my DOS window, even with both the options set.

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

It appears that your DOS window does not support ANSI colors.

from crayon.

sthupakula-rms avatar sthupakula-rms commented on June 1, 2024

Thank you. I found the solution here:
This can be used within R script by calling the exe like this
system("D:/completePath/x64/ansicon.exe -p")

and then using regular crayon code! Happier than ever!

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

I wonder if we could somehow autodetect when ansicon is running.

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

OK, from 467939b ANSICON is auto-detected, and 8 colors are used. Let me know if you have problems.

from crayon.

ffollett avatar ffollett commented on June 1, 2024

I think I'm experiencing something similar. I had crayon working properly in RStudio, but did a fresh install of Windows yesterday (and of R and RStudio) and now it's broken.

It works properly in the console, but when I save what I've done in a console to a script and run it in the RStudio terminal (set to PowerShell), it doesn't color the text and just shows me the markup or whatever that is:

#test.R
library(crayon)
packageVersion("crayon")
cat(green("Hello World"),"\n")
> Rscript test.R
[1] '1.3.4'
?[32mHello World?[39m

R Version 3.6.1, R Studio v1.2.1335, Platform: x86_64-w64-mingw32/x64 (64-bit)

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

Apparently, your powershell does not support ANSI colors.

from crayon.

ffollett avatar ffollett commented on June 1, 2024

It definitely supports coloring, but it looks like it uses different escape sequences. More info here.
image
Perhaps as mentioned above, if you could programaticaly detect Windows Powershell, crayon could use an alternate escape sequence?

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

No, the \033 is the same as $([char]27):

❯ as.integer(charToRaw("\033"))
[1] 27

from crayon.

ffollett avatar ffollett commented on June 1, 2024

That's generally true, but windows has to be different. Powershell doesn't use \ as an excape character (because windows uses it for file paths), so \033 is just interpreted as a char string, not the octal bash understands it as. Hence, you have to embed an expression, such as $([char]27).

image

from crayon.

gaborcsardi avatar gaborcsardi commented on June 1, 2024

\033 is interpreted by R already.

from crayon.

2005m avatar 2005m commented on June 1, 2024

Color in a windows shell is definitely possible. Here is an example:
https://stackoverflow.com/questions/9203362/c-color-text-in-terminal-applications-in-windows
Git and GCC have colored output in windows terminal. As usual someone just need to do it...I might give it a try if I am bored.

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.