Git Product home page Git Product logo

cli's People

Contributors

assignuser avatar bairdj avatar davisvaughan avatar gaborcsardi avatar hadley avatar indrajeetpatil avatar jennybc avatar jeroen avatar jimhester avatar jonocarroll avatar justin-mills-fws avatar kevinushey avatar krlmlr avatar lionel- avatar markedmondson1234 avatar michaelchirico avatar multimeric avatar olivroy avatar romainfrancois avatar rossellhayes avatar salim-b avatar sgibb avatar shians avatar simonpcouch avatar sjentsch avatar sthibaul avatar timtaylor avatar tzakharko avatar zachary-foster avatar zkamvar 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

cli's Issues

boxx doesn't work in a loop

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

Spinners

At least one for Unicode, and one fallback.

cat_line() etc don't respect width

withr::with_options(list(width = 20), cli::cat_rule())
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────

Colors in R Session Running Under Rstudio Terminal

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.

image

This is a pretty obscure use case, so probably not worth dealing with unless its trivial to fix. The tempfile thing is unrelated.

cli::cli: some way to define new inline tags

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.

Crayon prints escape sequences, does not apply colors in neovim-qt :terminal

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?

Generic style-able components

Intro

In addition to just status display, as in #24.

Block elements

  • Headers, at least three levels: h1, h2, h3, etc.
  • Text
  • Verbatim text
  • Markdown text
  • Paragraph: par
  • Block quote: blockquote
  • Bulleted list: ul
  • Ordered list: ol
  • Definition list: dl
  • Code block: blockcode
  • Alert (success, danger, warning, info): alert
  • Progress bar: progressbar
  • Table: table

Inline elements.

These can be used via embedded markup, see below.

  • inline code: code
  • emphasis: emph
  • strong emphasis: strong
  • package name: pkg
  • function name (maybe with package?): func
  • argument name: arg
  • keyboard keys: key
  • file: file
  • email: email
  • url: url
  • variable: var
  • environment variable: envvar

Inline markup

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.

Cross-package issues

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.

Helpers for error messages

(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, ...
  • Number formatting (e.g. set big mark)
  • Commas + truncation
  • Standard wrappers for argument names, paths, expressions

LaTeX compatibility

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?

Options to customize default colors

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.

Detection of colour in non-interactive RStudio session

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.

Is cli.width an appropriate default width for rule* functions?

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.

cli_rule

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.

Status display

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
}
  • Should also autowrap text. Give paragraphs as vector?
  • Should also pick text colour automatically - convert colour to rgb, then to hcl, then switch based on luminance

How to use spinners in code?

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

Integrate cat helpers

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

ruler()

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

Rule needs to handle vectors

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

cli_sitrep()

Like usethis::proj_sitrep() this would give a situation report telling you precisely what is active (utf-8, colours, ...) and why.

Move imports to suggests

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.

Some wrappers around format?

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.

Respect RStudio console width

e.g.

console_width <- function() {
  rstudio <- Sys.getenv("RSTUDIO_CONSOLE_WIDTH")
  if (identical(rstudio, "")) {
    getOption("width", 80)
  } else {
    as.integer(rstudio)
  }
}

cli: before and after selectors

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.

Release 1.0.1

Prepare for release:

  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Polish NEWS
  • If new failures, update email.yml then revdepcheck::revdep_email_maintainers()

Perform release:

  • Create RC branch (for bigger releases)
  • Bump version (in DESCRIPTION and NEWS)
  • devtools::check_win_devel() (again!)
  • devtools::submit_cran()
  • pkgdown::build_site()
  • Approve email

Wait for CRAN...

  • Tag release
  • Merge RC back to master branch
  • Bump dev version
  • Write blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Template from r-lib/usethis#338

Error installing

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.

crayon thinks has_color() = TRUE in Rgui launched from ConEmu on Windows

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

Export crayon:::is_r_color and crayon:::style_from_r_color?

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.

Windows ESS can display colors in the terminal, though you don't enable it

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?

I have attached my screen shot below:
image

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.