Skip to content

Commit

Permalink
separate TUI prompts for existing Rprofile and non-existing Rprofile
Browse files Browse the repository at this point in the history
  • Loading branch information
radbasa committed Aug 27, 2024
1 parent f30ec68 commit adebc9f
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,51 @@
#'
#' @export
use_box_lsp <- function(file_path = ".Rprofile") {
response <- readline(
glue::glue("Would you like to create or modify the `{file_path}` file? (yes/No) ")
)
response <- substr(response, 1, 1)
if (!(response == "Y" || response == "y")) {
cli::cli_abort("`{file_path}` file creation/modification cancelled!")
}

rprofile <- fs::path_package("box.lsp", "Rprofile.R")
to_write <- readLines(rprofile)

tryCatch({
if (file.exists(file_path)) {
response <- readline(
cli::cli(
cli::cli_alert(
c(
"`{file_path}` exists. Lines will be added to the end of this file. ",
"Would you like to continue (yes/No)"
),
wrap = TRUE
)
)
)
response <- substr(response, 1, 1)
if (!(response == "Y" || response == "y")) {
cli::cli_inform("`{file_path}` file append cancelled.")
return(invisible(NULL))
}

cli::cli_alert_info(
"{file_path} exists. Will append {{box.lsp}} configuration lines to the file."
"Appending {{box.lsp}} configuration lines to the `{file_path}`."
)
write("", file = file_path, append = TRUE)
} else {
response <- readline(
cli::cli(
cli::cli_alert(
"Would you like to create `{file_path}` with {{box_lsp}} configuration? (yes/No)",
wrap = TRUE)
)
)
response <- substr(response, 1, 1)
if (!(response == "Y" || response == "y")) {
cli::cli_inform("`{file_path}` file creation cancelled.")
return(invisible(NULL))
}

cli::cli_alert_info(
"Creating `{file_path}` with {{box.lsp}} configuration."
)
}

write(to_write, file = file_path, append = TRUE)
cli::cli_alert_success(
c(
Expand Down

0 comments on commit adebc9f

Please sign in to comment.