Skip to content

Commit

Permalink
Merge pull request #1187 from olivroy/color
Browse files Browse the repository at this point in the history
Add colored output
  • Loading branch information
IndrajeetPatil authored Mar 27, 2024
2 parents 634dce1 + 2489092 commit 208d9c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
9 changes: 6 additions & 3 deletions R/communicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ communicate_summary <- function(changed, ruler_width) {
cat("Status\tCount\tLegend \n")
cli::cat_bullet(
"\t", sum(!changed, na.rm = TRUE), "\tFile unchanged.",
bullet = "tick"
bullet = "tick",
bullet_col = "green"
)
cli::cat_bullet(
"\t", sum(changed, na.rm = TRUE), "\tFile changed.",
bullet = "info"
bullet = "info",
bullet_col = "cyan"
)
cli::cat_bullet(
bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an error."
bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an error.",
bullet_col = "red"
)
cli::cat_rule(width = max(40L, ruler_width))
}
Expand Down
20 changes: 11 additions & 9 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ transform_file <- function(path,
}
changed <- transform_code(path, fun = fun, ..., dry = dry)

bullet <- if (is.na(changed)) {
"warning"
} else if (changed) {
"info"
} else {
"tick"
}

if (!getOption("styler.quiet", FALSE)) {
cli::cat_bullet(bullet = bullet)
if (is.na(changed)) {
bullet <- "warning"
color <- "red"
} else if (changed) {
bullet <- "info"
color <- "cyan"
} else {
bullet <- "tick"
color <- "green"
}
cli::cat_bullet(bullet = bullet, bullet_col = color)
}
invisible(changed)
}
Expand Down

0 comments on commit 208d9c7

Please sign in to comment.