Skip to content

Commit

Permalink
#171 start on adding line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Jun 19, 2023
1 parent 09c36f7 commit a256a96
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions R/todos.R
Expand Up @@ -202,25 +202,56 @@ print.todos_df <- function(x, ...) {

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

if (package_available("cli")) {
cli_file <- function(x) {
cli::cli_text(sprintf("%s{.file %s}", pad, x))
}

cli_line <- function(file, line) {
line <- as.integer(line)
cli::cli_text(sprintf(
"{.href [%s](file://%s#%i)}",
sprintf(pat, line),
file,
line
))
}
} else {
cli_file <- function(file) {
collapse0(pad, crayon_blue(file))
}

cli_line <- function(file, line) {
line <- as.integer(line)
crayon_blue(sprintf(pat, line))
}
}

for (i in seq_along(splits)) {
catln(
collapse0(pad, crayon_blue(nm[i])),
apply(
splits[[i]][, c("line", type)],
1,
function(xi) {
paste(
crayon_blue(sprintf(pat, as.integer(xi[1]))),
if (nchar(xi[2]) > w) {
# TODO consider wrapping with respect to the line number?
collapse0(substr(xi[2], 1, max(1, w - 6)), " [...]")
} else {
xi[2]
}
# print the file
# print the line
cli_file(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
))
}
}

invisible(x)
Expand Down

0 comments on commit a256a96

Please sign in to comment.