r-lib / crayon Goto Github PK
View Code? Open in Web Editor NEW🖍️ R package for colored terminal output — now superseded by cli
Home Page: http://r-lib.github.io/crayon/
License: Other
🖍️ R package for colored terminal output — now superseded by cli
Home Page: http://r-lib.github.io/crayon/
License: Other
Maybe sm.options
does this: https://github.com/cran/sm/blob/master/R/utilities.r
When I submitted r-lib/covr@4024dc4 to win-builder it resulted in the following test errors (https://gist.github.com/jimhester/d59cda542277626e50e9).
Error 1 is un-releated to crayon, however errors 2 and 3 seem to be failure to load the crayon namespace on the build machine.
The relevant error messages are unknown terminal "cygwin" and traceback
Looking at the traceback I am guessing the issue is at R/has_color.r#L79-L81, for some reason cols does not being set, but the system command is also not throwing an error.
Sorry I don't have a good reproduceable example, I don't want to spam win-builder to create one. Any ideas on a fix?
I'm getting an installation error and am stumped. Any idea what the problem is and how to fix it?
> install.packages("crayon")
Installing package into ‘/home/xxx/R/x86_64-redhat-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://mirrors.nics.utk.edu/cran/src/contrib/crayon_1.3.2.tar.gz'
Content type 'unknown' length 656168 bytes (640 KB)
==================================================
downloaded 640 KB
* installing *source* package ‘crayon’ ...
** package ‘crayon’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
Error in if (inside_emacs() && emacs_version()[1] >= 23) { :
missing value where TRUE/FALSE needed
Error : unable to load R code in package ‘crayon’
ERROR: lazy loading failed for package ‘crayon’
* removing ‘/home/xxx/R/x86_64-redhat-linux-gnu-library/3.3/crayon’
The downloaded source packages are in
‘/tmp/RtmpIVwQXr/downloaded_packages’
Warning message:
In install.packages("crayon") :
installation of package ‘crayon’ had non-zero exit status
>
Thanks,
Brian
Trying to load the library causes the follow error:
library(crayon)
#> Error : .onLoad failed in loadNamespace() for 'crayon', details:
#> call: NULL
#> error: 'hasColorConsole' is not an exported object from 'namespace:rstudioapi'
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: elementary OS 0.4.1 Loki
Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.11 rstudioapi_0.6 knitr_1.16 whisker_0.3-2 devtools_1.13.1 xtable_1.8-2 R6_2.2.1
[8] tools_3.4.0 miniUI_0.1.1 clipr_0.3.2 withr_1.0.2 htmltools_0.3.6 shinyjs_0.9 yaml_2.1.14
[15] assertthat_0.2.0 digest_0.6.12 memoise_1.1.0 mime_0.5 reprex_0.1.1 compiler_3.4.0 jsonlite_1.4
[22] httpuv_1.3.3
http://no-color.org/ is a proposed standard for disabling color in CLI output - would crayon be able to implement this? - then all packages that use crayon will also gain support.
It would be nice if crayon also worked inside of knitr, rmarkdown, etc.
This probably requires some thinking to ensure that things are escaped correctly. (Or maybe it's the responsibility of evaluate to turn terminal escapes into the appropriate html spans)
cc @yihui
Consider:
> strsplit(" a b ", " ")
[[1]]
[1] "" "a" "b"
> col_strsplit(" a b ", " ")
[[1]]
[1] "" "a" "b" ""
I'd argue that the crayon
output is more correct. It is, however, different from what strsplit
does. Would you consider accepting a PR that "fixes" this? If no, not a big deal. I'm going to have to work around this issue anyway since for the time being I'm relying on the CRAN version of this package.
crayon::red("foo")
etc. fail to generate color codes when there is an active "output" sink. This is because crayon:::has_color()
returns FALSE in such cases, which appears to be due to the isatty(stdout())
test. "Message" sinks does not cause this problem.
> crayon:::has_color()
[1] TRUE
> isatty(stdout())
[1] TRUE
> sink(tempfile())
> x <- crayon:::has_color()
> y <- isatty(stdout())
> sink()
> x
[1] FALSE
> y
[1] FALSE
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.0 crayon_1.3.2
They support it now: https://travis-ci.org/hadley/colformat#L1313
AppVeyor: appveyor/ci#373
E.g.
style <- "underline"
add_style("foo", style)
or with pipes:
"foo" %>% add_style("underline")
A replacement version for substr()
is useful for colformat to truncate a string and replace the last character(s) with an ellipsis. The current code doesn't apply the styling of the previous text to the newly added ellipsis:
x[too_wide] <- paste0(crayon::col_substr(x[too_wide], 1, width - 1), "\u2026")
Hi,
I just started testing crayon, and when I type:
> show_ansi_colors()
r:0 g:0 b:0 r:0 g:0 b:1 r:0 g:0 b:2 r:0 g:0 b:3 r:0 g:0 b:4 r:0 g:0 b:5
r:0 g:1 b:0 r:0 g:1 b:1 r:0 g:1 b:2 r:0 g:1 b:3 r:0 g:1 b:4 r:0 g:1 b:5
...
I have a text output with no color.
The other examples seem to work fine, I can print styled text.
moreover:
> num_colors()
[1] 256
I am in a gnome-terminal, on ubuntu with TERM=xterm,
> library(crayon)
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux stretch/sid
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] crayon_1.3.2
I just noticed this:
trying URL 'https://cloud.r-project.org/src/contrib/crayon_1.3.4.tar.gz'
Content type 'application/x-gzip' length 658694 bytes (643 KB)
==================================================
downloaded 643 KB
It looks like most of the space is taken by images in inst/ which appear to be just there for a readme. Is it possible to move them somewhere else, or at least run optipng on them so they're smaller?
needed for tibble.
Hi,
crayon v 1.3.4
does not work in my R v3.4.3 running in gnome-terminal v3.22.2 or xterm.
> library(crayon)
> cat(blue("Hello", "world!\n"))
34mHello world!
39m>
> num_colors()
[1] 256
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 4.3
year 2017
month 11
day 30
svn rev 73796
language R
version.string R version 3.4.3 (2017-11-30)
35 nickname Kite-Eating Tree
Thank you so much for your help!
I looked into increasing coverage and it seems like there is a bit of code that isn't in use, such as:
data_frame
, which I think has been mostly superseded by the switch to matrices that I made a while backI can submit a PR addressing those plus other low hanging fruit if you're interested. I imagine there is a reason why disposable.r
is in the package though.
In progress on Azure
Compare:
cat(bgGreen("hello ", reset("there"), "yo"), "\n")
cat(bgGreen("hello ", bgRed("there"), "yo"), "\n")
As an image:
Ideally the "yo" would be green for the first expression too. I think the problem might be at this line whereby you replace any prior closing tags with opening tags and move the closing tags to the end. However, because the closing tag for reset
doesn't match any closing tags for any of the other styles, this doesn't work.
A possible solution would be to replace the closing tag for reset
with every possible closing tag concatenated, which I think should work with fairly minimal changes, though will add a bunch of stray closing tags whenever one uses reset
. That shouldn't affect anything though.
Let me know if you'll consider a pull request for this.
Hi
Would it be possible to enable the crayon
package to display messages within the R terminal in colors depending on the data type (or type of message) as it is possible with the colorout
package?
For example, if I hit
> a
Error: object 'a' not found
in the R terminal, the default color of the text "Error: object 'a' not found" is the color of the used terminal (e.g. black). When the colorout
package is loaded, the text can appear in, for example, red.
Unfortunately, the colorout
package interferes with the colored output of other functions, for example, devtools::install_github()
.
Thank you very much
If possible...
Just in cases the user wants to use them directly.
Hello, I test one function in a university server with version is 3.2.5 and when execute this lines:
warningstyle <- crayon::make_style(WarningStyle = rgb(1,0.2,0), bg = FALSE)
errorstyle <- crayon::make_style(ErrorStyle = "red", bg = FALSE)
successstyle <- crayon::make_style(SucessStyle = rgb(0,1,0), bg = FALSE)
Makes this error
Error in my_styles[[name]] <<- ansi_seq :
no se puede cambiar el valor de un vínculo bloqueado para 'my_styles'
Thanks for your time. When I execute a predefined style appear without color (black)
I.e. red(c("foo", "bar"))
should do something reasonable. Right now it collapses to foobar
, which is probably not reasonable.
crayon::num_colors()
sometimes returns just 1
, which causes undesired results with make_style()
. The error occurs for me after building a package with ctrl+shift+b, though I do not know if this is consistent way to reproduce the error.
Using crayon::num_colors(forget = TRUE)
always returns the correct number of colors. Maybe this should be the default?
I am using Rstudio Version 1.1.338
Minor corner case:
> substr(character(), 1, 0)
character(0)
> col_substr(character(), 1, 0)
Error in nstart - 1 : non-numeric argument to binary operator
Possibly related to some of the issues discussed in #27. I'll try to look at this too as I resolve #27 issues assuming you're okay with the general path I'm taking there.
Related, though less of an issue (more of an error message tweak):
> col_substr("hello", integer(), integer())
Error in if (pos < 1) { : missing value where TRUE/FALSE needed
> substr("hello", integer(), 1)
Error in substr("hello", integer(), integer()) : invalid substring arguments
Not sure how much you care, but I think that the current rgb -> ansi256 colour mapping is fairly inaccurate and could be fixed fairly easily.
Here's a case I have run into. The colour "#ADB9CA" is a mid gray, very slightly blue.
With crayon it renders the blue quite strongly:
In rainbowrite I ported code from the rainbow paint gem. It's not very long.
Would you like a PR that does the translations this way?
Ideally it would be nice if something like the following syntax would work.
library(crayon)
glue::glue("{blue}foo{red}bar{reset}baz")
I think it may be possible by defining a as.character.crayon
method that just outputs the escapes for the crayon object (if any).
Easy, something along https://github.com/jbnicolai/ansi-256-colors
Need a separate way to specify them, actually, because using grey when red = green = blue does not give a good result. See the output of show_ansi_colors()
.
No crayon effect is added to my console output and not sure what I've to do extra. Any help please?
> cat(underline('hi'))
hi>
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] crayon_1.3.4
loaded via a namespace (and not attached):
[1] compiler_3.4.0
>
On the screen.
My test case, load the packages "GenomicRanges" and "crayon" in R. Then try to run start() on a GRanges object, and it fails to find the appropriate start() function. As I loosely understand generic functions, the presence of a non-generic function overrides or at least confounds the process of dispatching a generic function.
I note that start() also masks the generic function stats::start(), which is an easier reproducible case::
start(1:10);
library(crayon);
start(1:10);
stats::start(1:10);
Final note: I really appreciate this package! I had been using the officially retired xterm256 package which I had kept a copy of for my own purposes -- I am much happier using a legit R package, and color has been extremely useful for my daily viewing of R console output. :-)
Please add support for powershell or cmd (+ansicon)
Now, I can output colored text in powershell (cmd+ansicon) using:
cat("\033[32;1m OK \033[0m\n")
but crayon functions don't work!
> make_style(col2rgb("peachpuff"))
Crayon style function, : example output.
Warning message:
In if (is_builtin_style(style)) { :
the condition has length > 1 and only the first element will be used
crayon::blue("asdf")
#> Error: 'hasColorConsole' is not an exported object from 'namespace:rstudioapi'
Another corner case:
> col_strsplit(letters[1:2], letters[1:2])
[[1]]
[1] "" ""
[[2]]
[1] "b"
Warning message:
In gregexpr(...) :
argument 'pattern' has length > 1 and only the first element will be used
> strsplit(letters[1:2], letters[1:2])
[[1]]
[1] ""
[[2]]
[1] ""
I suspect almost no-one relies on split args with length > 1, but just making a note of it here in case some day I motivate to fix it. Unfortunately not completly trivial since gregexpr
doesn't recycle.
message(crayon::make_style("hotpink")("asdfa"))
I noticed that message
and stop
coerce numbers to character under the hood, but crayon
doesn't do this:
> message(5)
5
> message(crayon::green(5))
Error in mypaste(...) : Need character strings
> packageVersion("crayon")
[1] ‘1.3.2’
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.