r-lib / cli Goto Github PK
View Code? Open in Web Editor NEWTools for making beautiful & useful command line interfaces
Home Page: https://cli.r-lib.org/
License: Other
Tools for making beautiful & useful command line interfaces
Home Page: https://cli.r-lib.org/
License: Other
I have been trying to install tidyverse using both an ubuntu environment (14.04.5) and a macOS (10.13.1), and both have failed with the cli package.
macOS:
> install.packages("tidyverse")
There is a binary version available but the source version is later:
binary source needs_compilation
tidyverse 1.1.1 1.2.0 FALSE
installing the source package ‘tidyverse’
trying URL 'https://cran.rstudio.com/src/contrib/tidyverse_1.2.0.tar.gz'
Content type 'application/x-gzip' length 61531 bytes (60 KB)
==================================================
downloaded 60 KB
Warning in strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
unknown timezone 'default/America/New_York'
* installing *source* package ‘tidyverse’ ...
** package ‘tidyverse’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error : .onAttach failed in attachNamespace() for 'tidyverse', details:
call: NULL
error: object ‘col_align’ is not exported by 'namespace:crayon'
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/tidyverse’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/tidyverse’
Warning in install.packages :
installation of package ‘tidyverse’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/hh/1z5wqsnn2y71_j1rllj44yhw0000gp/T/RtmpFQ9sgT/downloaded_packages’
Ubuntu:
> install.packages("tidyverse",dependencies = T)
Installing package into ‘/home/<username>/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
also installing the dependency ‘cli’
trying URL 'https://cran.rstudio.com/src/contrib/cli_1.0.0.tar.gz'
Content type 'unknown' length 1933874 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
trying URL 'https://cran.rstudio.com/src/contrib/tidyverse_1.2.0.tar.gz'
Content type 'unknown' length 61531 bytes (60 KB)
==================================================
downloaded 60 KB
* installing *source* package ‘cli’ ...
** package ‘cli’ successfully unpacked and MD5 sums checked
** R
** preparing package for lazy loading
Error : object ‘col_align’ is not exported by 'namespace:crayon'
ERROR: lazy loading failed for package ‘cli’
* removing ‘/home/<username>/R/x86_64-pc-linux-gnu-library/3.3/cli’
Warning in install.packages :
installation of package ‘cli’ had non-zero exit status
ERROR: dependency ‘cli’ is not available for package ‘tidyverse’
* removing ‘/home/<username>/R/x86_64-pc-linux-gnu-library/3.3/tidyverse’
Warning in install.packages :
installation of package ‘tidyverse’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmp5x4iWQ/downloaded_packages’
Additionally I cannot install the cli package alone as it reports the same issue with namespace:crayon. Please advise.
Prepare for release:
devtools::check_win_devel()
rhub::check_for_cran()
revdepcheck::revdep_check(num_workers = 4)
email.yml
then revdepcheck::revdep_email_maintainers()
Perform release:
devtools::check_win_devel()
(again!)devtools::submit_cran()
pkgdown::build_site()
Wait for CRAN...
Template from r-lib/usethis#338
So that apps can opt in.
Either using the progress package, or not.
cat_line <- function(..., file = "") {
cat(..., "\n", sep = "", file = file)
}
cat_kable <- function(x, ..., file = "") {
cat(kable(x, row.names = FALSE), sep = "\n", file = file)
cat_line(file = file)
}
cat_header <- function(..., level = 1, file = "") {
cat(bold(paste0(strrep("#", level), " ", ...)), "\n", sep = "", file = file)
cat_line(file = file)
}
cat_bullet <- function(..., file = "") {
cat_line("* ", ..., file = file)
}
cat_print <- function(x, file = "") {
if (!identical(file, "")) {
sink(file)
on.exit(sink(NULL))
}
print(x)
}
So you don't need to import both crayon and cli.
Would also use paste0()
instead of paste()
https://community.rstudio.com/t/tidyverse-1-2-1-knitting-to-pdf-issue/2880
I think we can detect this (at least for knitr) by inspecting options.
e.g.
console_width <- function() {
rstudio <- Sys.getenv("RSTUDIO_CONSOLE_WIDTH")
if (identical(rstudio, "")) {
getOption("width", 80)
} else {
as.integer(rstudio)
}
}
I am on Win10, neovim 3.1 and neovim-qt. When I use :terminal
to run ls --color=always
I get nicely colored output. When I open R
and run library(tidyverse)
, which uses crayon
, I see escape sequences instead of colors:
-- ?[1mAttaching packages?[22m --------------------------------------- tidyverse 1.2.1 --
?[32mv?[39m ?[34mggplot2?[39m 3.0.0 ?[32mv?[39m ?[34mpurrr ?[39m 0.2.5
?[32mv?[39m ?[34mtibble ?[39m 1.4.2 ?[32mv?[39m ?[34mdplyr ?[39m 0.7.7
?[32mv?[39m ?[34mtidyr ?[39m 0.8.1 ?[32mv?[39m ?[34mstringr?[39m 1.3.1
?[32mv?[39m ?[34mreadr ?[39m 1.1.1 ?[32mv?[39m ?[34mforcats?[39m 0.3.0
Is neovim-qt :terminal on Windows not supported or am I doing something wrong? If this is not the right place to address this issue, could you point in the right direction?
(Meta issue, will edit as I come across more small helpers):
dir_copy(c("foo", NA_character_, "bar", NA_character_), "blah")
#> Error: `path` must not have missing values
#> NAs found at 1,000,000 locations: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
In addition to just status display, as in #24.
h1
, h2
, h3
, etc.par
blockquote
ul
ol
dl
blockcode
alert
progressbar
table
These can be used via embedded markup, see below.
code
emph
strong
pkg
func
arg
key
file
email
url
var
envvar
Inline markup can be used via glue
. E.g.
"The {pkg processx} package..."
This is the same as
"The {pkg(\"processx\")} package..."
but easier to read and write. If the package name is in a variable, then you can simply use
"The {pkg(mypkg)} package..."
This syntax is not final.
One challenging part here is to have a well defined behavior when multiple packages use these components at the same time. E.g. the first package starts a paragraph, the second package issues an alert
, etc.
Either by vectorising or by throwing a clean error
cli::rule(c("a", "b"))
#> Warning in if (nchar(left)) {: the condition has length > 1 and only the
#> first element will be used
#> Warning in if (x <= 0) return(""): the condition has length > 1 and only
#> the first element will be used
#> Error in rep(char, x): invalid 'times' argument
I'm colorblind and use a dark theme in my editor. Whenever a package uses crayon::red()
, I can't see the text at all. Would it be possible to add an options system to let users to specify different colors to use for the base crayon
color functions? For example, the option to specify options(crayon.red = "coral3")
to use the "coral3"
color instead of the base R "red"
color for red text.
If this is reasonable, I would be happy to do a pull request.
Most terminals (except on OS X) have true color support. crayon should, too
It adds a lot of non-trivial dependencies and might be better in another package.
has_color()
returns TRUE
within non-interactive RStudio:
# Within RStudio:
callr::r(function() crayon::has_color())
#> [1] TRUE
# Outside RStudio:
callr::r(function() crayon::has_color())
#> [1] FALSE
I think this is because the rstudio_with_ansi_support()
check comes before the isatty()
check:
# Within RStudio:
callr::r(function() crayon:::rstudio_with_ansi_support() && sink.number() == 0)
#> [1] TRUE
callr::r(function() isatty(stdout()))
#> [1] FALSE
# Outside RStudio:
callr::r(function() crayon:::rstudio_with_ansi_support() && sink.number() == 0)
#> [1] FALSE
callr::r(function() isatty(stdout()))
#> [1] FALSE
Happy to send a PR to inverse the branches if that diagnostic looks right.
Hi,
This is an awesome package. Thank you for taking the time to write it.
I wanted to point out that I use windows ESS and it works fine, but I have to manually enable cryaon as follows:
options(crayon.enabled=TRUE)
I'm unsure why you default to windows/ESS not displaying colors. Can this be changed?
For common cases of left, right, and center aligning. Not sure if it belongs in this package, but it's somewhat related to drawing boxes because it makes columns the same width.
Could also include more sophisticated alignment on decimal place along with specified number of sig figs.
Not sure if this should be exported or not but it's sometimes useful for debugging
ruler <- function(width = console_width()) {
x <- seq_len(width)
y <- rep("-", length(x))
y[x %% 5 == 0] <- "+"
y[x %% 10 == 0] <- crayon::bold(as.character((x[x %% 10 == 0] %/% 10) %% 10))
cat(y, "\n", sep = "")
cat(x %% 10, "\n", sep = "")
}
Currently, cli has a very heavy dependency tree:
cli (1.0.0.9002)
├─assertthat (0.2.0)
├─crayon (1.3.4)
│ └─withr (2.1.2)
├─fansi (0.3.0)
├─glue (1.3.0)
│ ├─magrittr (1.5)
│ ├─crayon (1.3.4)
│ │ └─withr (2.1.2)
│ ├─stringr (1.3.1)
│ │ ├─glue (1.3.0)
│ │ ├─magrittr (1.5)
│ │ └─stringi (1.2.4)
│ └─withr (2.1.2)
├─progress (1.2.0)
│ ├─hms (0.4.2)
│ │ ├─crayon (1.3.4)
│ │ │ └─withr (2.1.2)
│ │ ├─pkgconfig (2.0.2)
│ │ └─rlang (0.2.2)
│ │ └─crayon (1.3.4)
│ │ └─withr (2.1.2)
│ ├─prettyunits (1.0.2)
│ │ ├─magrittr (1.5)
│ │ └─assertthat (0.2.0)
│ ├─R6 (2.2.2)
│ ├─crayon (1.3.4)
│ │ └─withr (2.1.2)
│ ├─Rcpp (0.12.18)
│ └─withr (2.1.2)
├─R6 (2.2.2)
├─selectr (0.4-1)
│ ├─xml2 (1.2.0)
│ │ ├─magrittr (1.5)
│ │ └─Rcpp (0.12.18)
│ ├─stringr (1.3.1)
│ │ ├─glue (1.3.0)
│ │ │ ├─magrittr (1.5)
│ │ │ ├─crayon (1.3.4)
│ │ │ │ └─withr (2.1.2)
│ │ │ ├─stringr (1.3.1)
│ │ │ └─withr (2.1.2)
│ │ ├─magrittr (1.5)
│ │ └─stringi (1.2.4)
│ └─R6 (2.2.2)
├─withr (2.1.2)
└─xml2 (1.2.0)
├─magrittr (1.5)
└─Rcpp (0.12.18)
I think we need to move as many packages as possible to suggests so that we can use cli as the single entry point to command line styling across all r-lib and tidyverse packages.
To make me happy?
Many symbols do not render properly in a LaTeX document: LaTeX.pdf. What's the best way to deal with this?
We can detect if LaTeX output is active, r-lib/pillar#61 (comment):
knitr:::is_latex_output()
. This function was exported recently in the devel version of knitr.
Should we work along these lines? Or should knitr (or even the user) just set the cli.unicode
option?
And implement a fallback to the "classic" style.
Inspired by https://github.com/MichaelCereda/pretty-cli#readme and @gaborcsardi's idea for testthat output
cat_status <- function(status, details, info = NULL,
status_col = NULL,
details_col = status_col) {
status <- apply_style(paste0(" ", status, " "), status_col, bg = TRUE)
width <- ansistrings::ansi_nchar(status, type = "width") + 1
details <- apply_style(str_indent(details, 0, width), details_col)
cat_line(status, " ", details)
if (!is.null(info)) {
cat_line(str_indent(info, width, width))
}
invisible()
}
str_indent <- function(x, indent = 0, exdent = indent) {
if (indent > 0) {
indent <- paste0(rep(" ", indent), collapse = "")
x <- gsub("^", indent, x)
}
if (exdent > 0) {
indent <- paste0("\n", paste0(rep(" ", exdent), collapse = ""))
x <- gsub("\\n", indent, x)
}
x
}
This seems related to r-lib/crayon#56, except this is running R from an Rstudio terminal, instead of the normal Rstudio console. Setting forget to TRUE fixes it.
This is a pretty obscure use case, so probably not worth dealing with unless its trivial to fix. The tempfile
thing is unrelated.
The active binding is evaluated when imported into another package. This causes r-lib/sessioninfo#14 and also tidyverse/reprex#150 (comment)
The CRAN package of cli is implemented differently, there is no active binding, symbol
is created at load time, and this suffers from the same problem.
Like usethis::proj_sitrep()
this would give a situation report telling you precisely what is active (utf-8, colours, ...) and why.
Thanks for the amazing package!
A new package multicolor
makes heavy use of crayon
. There is a PR for it to be integrated into the cowsay
package by @sckott and friends.
A new cowsay
release to CRAN would also require that multicolor
be on CRAN. Currently multicolor
uses two internal crayon
functions, is_r_color
and style_from_r_color
and so wouldn't pass a CRAN check.
Would it be possible to export these two functions in the next release of crayon
? If you'd rather not export and have other ideas I'd be totally open to them. is_r_color
would be feasible to copy the code for, but style_from_r_color
wouldn't be, imo.
I got here from: tidyverse/tibble#396, which points to crayon rather than tibble/pillar being the problem. I guess this is probably slightly obscure, but the problem is as follows. I was getting this issue with tibble printing:
> options(crayon.enabled = TRUE)
> tibble(x = 1:5, y = 1, z = x ^ 2 + y)
�[90m# A tibble: 5 x 3�[39m
x y z
�[3m�[90m<int>�[39m�[23m �[3m�[90m<dbl>�[39m�[23m �[3m�[90m<dbl>�[39m�[23m
�[90m1�[39m 1 1 2
�[90m2�[39m 2 1 5
�[90m3�[39m 3 1 10
�[90m4�[39m 4 1 17
�[90m5�[39m 5 1 26
> options(crayon.enabled = FALSE)
> tibble(x = 1:5, y = 1, z = x ^ 2 + y)
# A tibble: 5 x 3
x y z
<int> <dbl> <dbl>
1 1 1 2
2 2 1 5
3 3 1 10
4 4 1 17
5 5 1 26
in Rgui on Windows. I tracked the issue back to the fact that if you launch Rgui from the Start Menu or Windows command prompt, you get:
> crayon::has_color()
[1] FALSE
but if you launch Rgui from ConEmu, you get:
> crayon::has_color()
[1] TRUE
even though you actually don't have color support. Setting option(crayon.enabled = FALSE)
solves the problem but it's sufficiently conditional as to be confusing.
I guess the issue is that this line: https://github.com/r-lib/crayon/blob/3e751fbff44896abcd5e58eac37655564b61c22c/R/has_color.r#L68 is TRUE
in both cases because the R session inherits the ConEmu environment variables.
A possible way to distinguish would be to grab:
> .Platform$GUI
[1] "Rgui"
versus
> .Platform$GUI
[1] "RTerm"
and then only enable crayon if (.Platform$GUI == "RTerm" && Sys.getenv("ConEmuANSI") == "ON")
.
As a reference, session info is the same in both instances:
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.1 crayon_1.3.4
Sg analogous to <span>
, but in a way that allows new classes. Maybe just
"blah {span.class foobar} blah"
The shorter
"blah {class foobar} blah"
would be better, though.
Some of the inline tags are really tags (emph, strong, code), but the others just classes on a span. Maybe all of them should be classes.
The code below only displays the first and third boxx. I have tried this within RStudio and windows command line R.
cli::boxx("Hello out here!", padding = 1, background_col = "brown")
x <- TRUE
while (x) {
cli::boxx("Hello in here!", padding = 1, background_col = "brown")
x <- FALSE
}
cli::boxx("Hello out here again!", padding = 1, background_col = "brown")
Hi,
I couldn't figure out how to use the spinners in code, while an lapply function is running.
What should it look like? Maybe it could be useful to add it to the readme/package pdf?
Thanks!
Greg
I think cli should import crayon >= 1.3.4 since it seems as col_allign(), which cli imports from crayon, was only exported after release of crayon 1.3.4.
The problem came up in styler when someone had only crayon 1.3.2.
r-lib/styler#307 (comment)
withr::with_options(list(width = 20), cli::cat_rule())
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────
I am pretty sure the link it the following line should be [symbol]
rather than [symbols]
. The current version links to graphics::symbols
which seems unrelated to this package.
Line 10 in 56538e3
At least one for Unicode, and one fallback.
To style everything
Proper ::before
and ::after
selectors are needed. These are not styles, but selectors. Right now we get this:
❯ cli::cli$alert_success("{pkg foobar} is good")
✔ ✔ foobar is good
Because the embedded span
also has the before
style.
Editors other than RStudio have console windows that can have line truncation dynamically toggled, and can be scrolled horizontally as well as vertically. This can be utilised to set a large value for the cli.width
option and have R output print without columns getting moved onto new lines or getting removed altogether (like with Tibbles).
Using this setting creates an annoyance though with packages that use the cli::rule
function since they may print many thousands of useless -
or =
characters to the console. E.g.
Could console_width()
look for some other option in preference to cli.width
? maybe cli.visible.width
or rule.width
?
Edit: The major annoyance actually comes in running testthat
, where the frequent use of rule
in the output seems to slow everything down.
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.