Skip to content

Commit

Permalink
#171 simplify todos output
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Jun 19, 2023
1 parent f665487 commit adbc323
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions R/todos.R
Expand Up @@ -190,45 +190,18 @@ do_todo <- function( # nolint: cyclocomp_linter.
#' @export
print.todos_df <- function(x, ...) {
# TODO Add a limit for number of TODOs to show?
type <- attr(x, "todos_type")

n <- max(nchar(x[["line"]]), 0)
w <- getOption("width") - n - 3 # 4??
pad <- collapse0(rep(" ", n + 3))
pat <- sprintf("[%%%i.i]", n)

splits <- split(x, x[["file"]])
nm <- names(splits)

cat0(sprintf("Found %d %s:\n", nrow(x), toupper(type)))

for (i in seq_along(splits)) {
# TODO can I preserve white space?
cli::cli_text(sprintf("%s{.file %s}", pad, nm[i]))

for (j in seq_along(splits[[i]]$todo)) {
info <- splits[[i]]
text <-
if (nchar(info$todo[j])) {
collapse0(
substr(info$todo[j], 1, max(1, w - 6)),
" [...]"
)
} else {
info$todo[j]
}

cli::cli_text(sprintf(
"{.href [%s](file://%s#%i)} %s",
sprintf(pat, info$line[j]),
info$file[j],
info$line[j],
text
))
}
cat0(sprintf("Found %d %s:\n", nrow(x), toupper(attr(x, "todos_type"))))

for (i in seq_len(nrow(x))) {
cli::cli_text(sprintf(
"{.file %s#%i} %s",
x$file[i],
x$line[i],
x$todo[i]
))
}

invisible(x)
return(invisible(x))
}

# conditions --------------------------------------------------------------
Expand Down

0 comments on commit adbc323

Please sign in to comment.