Comments (8)
The idea is that you will print those strings to stdout ASAP, and if stdout does not support color, then we don't use the ANSI escape codes. So this is as designed.
Most programs work the same way, e.g. just try
ls -G
ls -G > /tmp/x
If you want to force the ANSI sequences, use the crayon.enabled.
and crayon.colors
options. E.g.
withr::with_options(
c(crayon.enabled = TRUE, crayon.colors = 256),
red("I am red")
)
from crayon.
I see; makes sense.
Then a follow up, shouldn't there be test against stderr()
if you "plan" to print to stderr? I understand this is not easy to detect / support automatically; maybe an argument output = "stdout"
?
FYI, I bumped into this when trying to conditionally display yellow("1 output sink")
to a customized prompt
function. I did find the workaround where I do if (crayon:::has_color()) options(crayon.enabled = TRUE)
when I first set up the prompt during .Rprofile
startup (where I can safely assume no sinks are active).
from crayon.
maybe an argument output = "stdout"?
argument to what function?
Maybe it could be an option, e.g. crayon.output
, but that will be cumbersome to change every time...
from crayon.
maybe an argument output = "stdout"?
argument to what function?
agree == "maybe" ;) In worst case, it's needed for all functions calling has_color()
... very tedious to use.
Could such an option be encapsulated in a convenient for_stderr()
wrapper, e.g. for_stderr(red("foo"))
? (not sure if with_stderr()
is good here).
from crayon.
for_stderr
is a good idea. How about calling it color_stderr
?
We could also have with_color
to shorten the with_options
call above.
from crayon.
color_stderr()
is better, but like with_color()
even more. Not sure what the argument / option name should be, e.g. target
, type
(cf. sink()
), ...?
For the output target, can see something like the following use cases:
with_color(..., target = "stdout"))
with_color(..., target = "stderr"))
with_color(..., target = c("stdout", "stderr")))
- outputting to both(?)with_color(..., target = "prompt"))
- neither stdout nor stderr, but prompt and readline-ish output (non-sinkable)with_color(..., target = "none"))
- disable coloringwith_color(..., target = "always"))
- enable coloring regardless of support(?)
from crayon.
Yeah, sg. like that.
from crayon.
OK, I decided not to do this for the next patch release. It is probably not commonly needed, and I am not yet sure what would be the right way to do. For now, please force color as a workaround.
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.