8000 GitHub - yutannihilation/cli at cli
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

yutannihilation/cli

 
 

Repository files navigation

cli

Draw Boxes, Rules, Trees in the R Console

Linux Build Status Windows Build status CRAN RStudio mirror downloads Coverage status

It integrates well with crayon for coloring the boxes or their content, and clisymbols to include Unicode characters in the boxes. It can also draw rules to make headers or footers in console output, and tree structures.

Installation

devtools::install_github("r-lib/cli")

Usage

library(cli)

Rules

Simple rule

rule()

Double rule

rule(line = 2)

Bars

rule(line = "bar2")

rule(line = "bar5")

Left label

rule(left = "Results")

Centered label

rule(center = " * RESULTS * ")

Colored labels

rule(center = crayon::red(" * RESULTS * "))

Colored line

rule(center = crayon::red(" * RESULTS * "), line_color = "red")

Custom line

rule(center = "TITLE", line = "~")

More custom line

rule(center = "TITLE", line = crayon::blue("~-"))

Even more custom line

rule(center = crayon::bgRed(" ", clisymbols::symbol$star, "TITLE",
  clisymbols::symbol$star, " "),
  line = "\u2582",
  line_color = "orange")

Boxes

Default box

boxx("Hello there!")

Change border style

boxx("Hello there!", border_style = "double")

Multiple lines

boxx(c("Hello", "there!"), padding = 1)

Padding

boxx("Hello there!", padding = 1)

boxx("Hello there!", padding = c(1, 5, 1, 5))

Margin

boxx("Hello there!", margin = 1)

boxx("Hello there!", margin = c(1, 5, 1, 5))

boxx("Hello there!", padding = 1, margin = c(1, 5, 1, 5))

Floating

boxx("Hello there!", padding = 1, float = "center")

boxx("Hello there!", padding = 1, float = "right")

Text color

boxx(crayon::cyan("Hello there!"), padding = 1, float = "center")

Backgorund color

boxx("Hello there!", padding = 1, background_color = "brown")

boxx("Hello there!", padding = 1, background_color = crayon::bgRed)

Border color

boxx("Hello there!", padding = 1, border_color = "green")

boxx("Hello there!", padding = 1, border_color = crayon::red)

Label alignment

boxx(c("Hi", "there", "you!"), padding = 1, align = "left")

boxx(c("Hi", "there", "you!"), padding = 1, align = "center")

boxx(c("Hi", "there", "you!"), padding = 1, align = "right")

A very customized box

star <- clisymbols::symbol$star
label <- c(paste(star, "Hello", star), "  there!")
boxx(
  crayon::white(label),
  border_style="round",
  padding = 1,
  float = "center",
  border_color = "tomato3",
  background_color="darkolivegreen"
)

Trees

You can specify the tree with a two column data frame, containing the node ids/labels, and the list of their children.

data <- data.frame(
  stringsAsFactors = FALSE,
  package = c("processx", "backports", "assertthat", "Matrix",
    "magrittr", "rprojroot", "clisymbols", "prettyunits", "withr",
    "desc", "igraph", "R6", "crayon", "debugme", "digest", "irlba",
    "rcmdcheck", "callr", "pkgconfig", "lattice"),
  dependencies = I(list(
    c("assertthat", "crayon", "debugme", "R6"), character(0),
    character(0), "lattice", character(0), "backports", character(0),
    c("magrittr", "assertthat"), character(0),
    c("assertthat", "R6", "crayon", "rprojroot"),
    c("irlba", "magrittr", "Matrix", "pkgconfig"), character(0),
    character(0), "crayon", character(0), "Matrix",
    c("callr", "clisymbols", "crayon", "desc", "digest", "prettyunits",
      "R6", "rprojroot", "withr"),
    c("processx", "R6"), character(0), character(0)
  ))
)
tree(data, root = "rcmdcheck")

An optional third column may contain custom labels. These can be colored as well:

data$label <- paste(data$package,
  crayon::blurred(paste0("(", c("2.0.0.1", "1.1.1", "0.2.0", "1.2-11",
    "1.5", "1.2", "1.2.0", "1.0.2", "2.0.0", "1.1.1.9000", "1.1.2",
    "2.2.2", "1.3.4", "1.0.2", "0.6.12", "2.2.1", "1.2.1.9002",
    "1.0.0.9000", "2.0.1", "0.20-35"), ")"))
  )
roots <- ! data$package %in% unlist(data$dependencies)
data$label[roots] <- crayon::cyan(crayon::italic(data$label[roots]))
tree(data, root = "rcmdcheck")

License

MIT © RStudio

About

Tools for making beautiful & useful command line interfaces

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 99.9%
  • Makefile 0.1%
0