GithubHelp home page GithubHelp logo

r-lib / crayon Goto Github PK

View Code? Open in Web Editor NEW
322.0 322.0 36.0 1.33 MB

🖍️ R package for colored terminal output — now superseded by cli

Home Page: http://r-lib.github.io/crayon/

License: Other

R 100.00%
r

crayon's People

Contributors

brodieg avatar cubranic avatar davisvaughan avatar dnusinow avatar e3bo avatar fmichonneau avatar gaborcsardi avatar jimhester avatar krlmlr avatar mrchypark avatar nfultz avatar rdiaz02 avatar richfitz avatar salim-b avatar vreuter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

crayon's Issues

error on load

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'
Session info
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  

Nested `reset` behaves differently to other styles

Compare:

cat(bgGreen("hello ", reset("there"), "yo"), "\n")
cat(bgGreen("hello ", bgRed("there"), "yo"), "\n")

As an image:

crayon

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.

`split` argument with length > 1 for `col_strsplit`

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.

Think about how to colour html output

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

crayon:::has_color() returns FALSE when an output sink is active

Issue

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.

Troubleshooting

No active output sink

> crayon:::has_color()
[1] TRUE
> isatty(stdout())
[1] TRUE

Active output sink

> sink(tempfile())
> x <- crayon:::has_color()
> y <- isatty(stdout())
> sink()
> x
[1] FALSE
> y
[1] FALSE

Details

> 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  

no coercion to character as in `base::message`

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’

warning in make_style() using rgb color

> 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

256 colour mapping

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.

target

With crayon it renders the blue quite strongly:

issue

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?

crayon::`col_substr()<-`

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")

Crayon and old R version (3.2.5)

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)

Output not colored in xterm and gnome-terminal

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!

Proper manual

  • chr
  • concat
  • crayon
  • has_color
  • has_style
  • strip_style
  • style
  • styles

R 3.4 console output not crayonized

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
> 

Ideas to make it easier to style text in conjunction with glue

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).

Package is very large

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?

R terminal messages in colors like in the colorout package?

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

crayon errors on winbuilder

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?

ANSI 256: fix greys

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().

windows shell support?

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 start() a generic function, so it does not mask start() functions from stats and GenomicRanges

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. :-)

`col_substr` with zero length vectors

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

Crayon fails to detect correct number of terminal colors in Rstudio

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

no colors printed by show_ansi_colors()

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

Increase Coverage

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 back
  • the code in disposable.r, which as far as I can tell isn't currently in use?

I 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.

Align `col_strsplit` to `strsplit`, warts and all?

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.

missing value where TRUE/FALSE needed

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

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.