From 24f58d1379d4f04617f7343824780eb5f0fbbe35 Mon Sep 17 00:00:00 2001 From: vedhav Date: Thu, 7 Nov 2024 14:09:35 +0530 Subject: [PATCH] fix: use ASCII charsets for the tree construction --- R/modules.R | 26 +++++++++++++------------- man/teal_modules.Rd | 2 +- tests/testthat/test-modules.R | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/R/modules.R b/R/modules.R index e1eccb6d12..d0099afd93 100644 --- a/R/modules.R +++ b/R/modules.R @@ -322,7 +322,7 @@ modules <- function(..., label = "root") { #' @rdname teal_modules #' @param is_last (`logical(1)`) Whether this is the last item in its parent's children list. -#' Affects the tree branch character used (└─ vs ├─) +#' Affects the tree branch character used (L- vs |-) #' @param parent_prefix (`character(1)`) The prefix inherited from parent nodes, #' used to maintain the tree structure in nested levels #' @param is_root (`logical(1)`) Whether this is the root node of the tree. Only used in @@ -345,9 +345,9 @@ format.teal_module <- function( x, indent = 0, is_last = FALSE, parent_prefix = "", what = c("datasets", "properties", "ui_args", "server_args", "transformers"), ...) { empty_text <- "NULL" - branch <- if (is_last) "└─" else "├─" + branch <- if (is_last) "L-" else "|-" current_prefix <- paste0(parent_prefix, branch, " ") - content_prefix <- paste0(parent_prefix, if (is_last) " " else "│ ") + content_prefix <- paste0(parent_prefix, if (is_last) " " else "| ") format_list <- function(lst, empty = empty_text, label_width = 0) { if (is.null(lst) || length(lst) == 0) { @@ -363,7 +363,7 @@ format.teal_module <- function( function(name) { sprintf( "%s%s (%s)", - paste0(content_prefix, "│ ", colon_space), + paste0(content_prefix, "| ", colon_space), name, crayon::silver(class(lst[[name]])[1]) ) @@ -391,35 +391,35 @@ format.teal_module <- function( if ("datasets" %in% what) { output <- paste0( output, - content_prefix, "├─ ", crayon::yellow("Datasets : "), paste(x$datanames, collapse = ", "), "\n" + content_prefix, "|- ", crayon::yellow("Datasets : "), paste(x$datanames, collapse = ", "), "\n" ) } if ("properties" %in% what) { output <- paste0( output, - content_prefix, "├─ ", crayon::blue("Properties:"), "\n", - content_prefix, "│ ├─ ", crayon::cyan("Bookmarkable : "), bookmarkable, "\n", - content_prefix, "│ └─ ", crayon::cyan("Reportable : "), reportable, "\n" + content_prefix, "|- ", crayon::blue("Properties:"), "\n", + content_prefix, "| |- ", crayon::cyan("Bookmarkable : "), bookmarkable, "\n", + content_prefix, "| L- ", crayon::cyan("Reportable : "), reportable, "\n" ) } if ("ui_args" %in% what) { ui_args_formatted <- format_list(x$ui_args, label_width = 19) output <- paste0( output, - content_prefix, "├─ ", crayon::green("UI Arguments : "), ui_args_formatted, "\n" + content_prefix, "|- ", crayon::green("UI Arguments : "), ui_args_formatted, "\n" ) } if ("server_args" %in% what) { server_args_formatted <- format_list(x$server_args, label_width = 19) output <- paste0( output, - content_prefix, "├─ ", crayon::green("Server Arguments : "), server_args_formatted, "\n" + content_prefix, "|- ", crayon::green("Server Arguments : "), server_args_formatted, "\n" ) } if ("transformers" %in% what) { output <- paste0( output, - content_prefix, "└─ ", crayon::magenta("Transformers : "), transformers, "\n" + content_prefix, "L- ", crayon::magenta("Transformers : "), transformers, "\n" ) } @@ -532,9 +532,9 @@ format.teal_modules <- function(x, indent = 0, is_root = TRUE, is_last = FALSE, new_parent_prefix <- " " #' Initial indent for root level } else { if (!is.null(x$label)) { - branch <- if (is_last) "└─" else "├─" + branch <- if (is_last) "L-" else "|-" header <- pasten(parent_prefix, branch, " ", crayon::bold(x$label)) - new_parent_prefix <- paste0(parent_prefix, if (is_last) " " else "│ ") + new_parent_prefix <- paste0(parent_prefix, if (is_last) " " else "| ") } else { header <- "" new_parent_prefix <- parent_prefix diff --git a/man/teal_modules.Rd b/man/teal_modules.Rd index 928562d0b1..486682e5e6 100644 --- a/man/teal_modules.Rd +++ b/man/teal_modules.Rd @@ -101,7 +101,7 @@ Transformers' \code{datanames} are added to the \code{datanames}. See \code{\lin \item{indent}{(\code{integer(1)}) Indention level; each nested element is indented one level more.} \item{is_last}{(\code{logical(1)}) Whether this is the last item in its parent's children list. -Affects the tree branch character used (└─ vs ├─)} +Affects the tree branch character used (L- vs |-)} \item{parent_prefix}{(\code{character(1)}) The prefix inherited from parent nodes, used to maintain the tree structure in nested levels} diff --git a/tests/testthat/test-modules.R b/tests/testthat/test-modules.R index 977751c174..b173d7b3e6 100644 --- a/tests/testthat/test-modules.R +++ b/tests/testthat/test-modules.R @@ -509,7 +509,7 @@ testthat::test_that("format.teal_modules returns proper structure", { testthat::expect_equal( gsub("\033\\[[0-9;]*m", "", format(appended_mods)), - "TEAL ROOT\n ├─ a\n │ ├─ Datasets : all\n │ ├─ Properties:\n │ │ ├─ Bookmarkable : FALSE\n │ │ └─ Reportable : FALSE\n │ ├─ UI Arguments : NULL\n │ ├─ Server Arguments : NULL\n │ └─ Transformers : NULL\n ├─ c\n │ ├─ Datasets : all\n │ ├─ Properties:\n │ │ ├─ Bookmarkable : FALSE\n │ │ └─ Reportable : FALSE\n │ ├─ UI Arguments : NULL\n │ ├─ Server Arguments : NULL\n │ └─ Transformers : NULL\n └─ c\n ├─ Datasets : all\n ├─ Properties:\n │ ├─ Bookmarkable : FALSE\n │ └─ Reportable : FALSE\n ├─ UI Arguments : NULL\n ├─ Server Arguments : NULL\n └─ Transformers : NULL\n" # nolint: line_length + "TEAL ROOT\n |- a\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : NULL\n | |- Server Arguments : NULL\n | L- Transformers : NULL\n |- c\n | |- Datasets : all\n | |- Properties:\n | | |- Bookmarkable : FALSE\n | | L- Reportable : FALSE\n | |- UI Arguments : NULL\n | |- Server Arguments : NULL\n | L- Transformers : NULL\n L- c\n |- Datasets : all\n |- Properties:\n | |- Bookmarkable : FALSE\n | L- Reportable : FALSE\n |- UI Arguments : NULL\n |- Server Arguments : NULL\n L- Transformers : NULL\n" # nolint: line_length ) })