Suggests: cli
#1246
Replies: 1 comment 1 reply
-
Something like this should work: diff --git a/R/class-workbook.R b/R/class-workbook.R
index 40f61409..fd197aa1 100644
--- a/R/class-workbook.R
+++ b/R/class-workbook.R
@@ -6855,28 +6855,44 @@ wbWorkbook <- R6::R6Class(
nImages <- length(self$media)
nCharts <- length(self$charts)
- showText <- "A Workbook object.\n"
+ out <- list(
+ title = "A Workbook object.\n",
+ sheets = self$get_sheet_names(),
+ order = self$sheetOrder
+ )
+
+ if (!isNamespaceLoaded("cli")) {
- ## worksheets
- if (nSheets > 0) {
- showText <- c(showText, "\nWorksheets:\n")
- sheetTxt <- sprintf("Sheets: %s", paste(exSheets, collapse = ", "))
+ cat(out$title)
- showText <- c(showText, sheetTxt, "\n")
+ ## worksheets
+ if (nSheets > 0) {
+ cat("\nWorksheets:\n")
+ cat(sprintf("Sheets: %s", paste(out$sheets, collapse = ", ")))
+ cat("\n")
+ } else {
+ cat("\nWorksheets:\n", "No worksheets attached\n")
+ }
+ if (nSheets > 0) {
+ cat(
+ sprintf("Write order: %s", stringi::stri_join(out$order, sep = " ", collapse = ", "))
+ )
+ }
} else {
- showText <-
- c(showText, "\nWorksheets:\n", "No worksheets attached\n")
- }
- if (nSheets > 0) {
- showText <-
- c(showText, sprintf(
- "Write order: %s",
- stringi::stri_join(self$sheetOrder, sep = " ", collapse = ", ")
- ))
- }
+ cli::cli_h1(out$title)
+ cli::cli_h3("{.bold Worksheets:}")
+ if (nSheets > 0) {
+ cli::cli_ul(out$sheets)
+ } else {
+ cli::cli_alert_danger("No worksheets attached")
+ }
+ if (nSheets > 0) {
+ cli::cli_h3("{.bold Order:}")
+ cli::cli_ul(as.character(out$sheets))
+ }
- cat(unlist(showText))
+ }
invisible(self)
},
Needs a change to a test, because |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If anybody would want to work on this, I would be willing to accept a PR that adds
cli
as an optional package that if loaded, or otherwise available, will improve our printing.Why don't I do it myself? Well, designing user interfaces obviously isn't my strong suit (the current default output is a bit ... random at best). What I absolutely want to avoid is a hard dependency. In the absence of
cli
the package should work just as is.Beta Was this translation helpful? Give feedback.
All reactions