Comments (20)
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.
run powershell then rterm.exe
and paste this:
cat("\033[32;1m OK \033[0m\n")
you will get colored output....
from crayon.
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.
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.
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.
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.
I also submitted an SO post
from crayon.
Confirmed: the RStudio 1.1 preview supports crayon
colors automatically. I had no idea.
from crayon.
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.
It appears that your DOS window does not support ANSI colors.
from crayon.
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.
I wonder if we could somehow autodetect when ansicon is running.
from crayon.
OK, from 467939b ANSICON is auto-detected, and 8 colors are used. Let me know if you have problems.
from crayon.
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.
Apparently, your powershell does not support ANSI colors.
from crayon.
It definitely supports coloring, but it looks like it uses different escape sequences. More info here.
Perhaps as mentioned above, if you could programaticaly detect Windows Powershell, crayon could use an alternate escape sequence?
from crayon.
No, the \033
is the same as $([char]27)
:
❯ as.integer(charToRaw("\033"))
[1] 27
from crayon.
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).
from crayon.
\033
is interpreted by R already.
from crayon.
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)
- Detection of color-capable output broken inside an RStudio Job run as a script HOT 1
- win10_build: argument is of length 0 HOT 1
- Backport palette support from cli
- Move `master` branch to `main` HOT 1
- Ns in DNAstringset greys out all text in console that follows HOT 2
- Force all warnings to use crayon? HOT 3
- Release crayon 1.4.2
- red$bold(X) results in : Error in gsub: input string 1 is invalid UTF-8 HOT 3
- Color detection Github Actions HOT 5
- Does not install on R 3.4 and R 3.5, on Windows HOT 1
- Release crayon 1.5.0
- Potential NAMESPACE/import issue? HOT 1
- Release crayon 1.5.1
- Partial argument name: read.table(..., comment = ";")
- crayon doesn't mark encoding on UTF-8 strings in some cases HOT 3
- num_ansi_colors ignores stream parameter HOT 1
- strip_style() returns garbled output in non-UTF-8 locale when UTF-8 characters are present HOT 2
- Release crayon 1.5.2
- Upkeep for crayon (2023)
- crayon update from CRAN
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crayon.