Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions R/daemon.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
render,
port,
host,
browse
browse,
quiet = FALSE,
.call = rlang::caller_env()
) {
# resolve target if provided
if (!is.null(target)) {
Expand Down Expand Up @@ -39,14 +41,14 @@
} else {
port <- find_port()
if (is.null(port)) {
stop("Unable to find port to start server on")
cli::cli_abort("Unable to find port to start server on.", call = .call)

Check warning on line 44 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L44

Added line #L44 was not covered by tests
}
}
}

# check for port availability
if (port_active(port)) {
stop("Server port ", port, " already in use.")
cli::cli_abort("Server port {port} already in use.", call = .call)

Check warning on line 51 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L51

Added line #L51 was not covered by tests
}

# command and target
Expand Down Expand Up @@ -75,6 +77,13 @@
# no browse (we'll use browseURL)
args <- c(args, "--no-browse")

# quiet mode
quiet_msg_suffix <- NULL
if (is_quiet(quiet)) {
args <- cli_arg_quiet(args)
quiet_msg_suffix <- " Set {.code quiet = FALSE} to have more information from quarto CLI output."

Check warning on line 84 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L81-L84

Added lines #L81 - L84 were not covered by tests
}

# add extra args
args <- c(args, extra_args)

Expand All @@ -92,10 +101,12 @@
init <- ""
while (!port_active(port)) {
quarto[[ps_key]]$poll_io(50)
cat(quarto[[ps_key]]$read_output())
if (isFALSE(quiet)) {
cat(quarto[[ps_key]]$read_output())
}

Check warning on line 106 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L104-L106

Added lines #L104 - L106 were not covered by tests
if (!quarto[[ps_key]]$is_alive()) {
stop_serve_daemon(command)
stop("Error starting quarto")
cli::cli_abort(c(x = "Error starting quarto.", quiet_msg_suffix))

Check warning on line 109 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L109

Added line #L109 was not covered by tests
}
}
quarto[[port_key]] <- port
Expand All @@ -105,22 +116,28 @@
if (is.null(quarto[[ps_key]])) {
return()
}
ro <- quarto[[ps_key]]$read_output()
cat(ro)
# Look at url to browse too in `quarto preview log`
if (
!isFALSE(browse) &&
is.null(quarto[[url_key]]) &&
grepl("Browse at https?://", ro)
) {
m <- regexec("Browse at (https?://[^ ]+)\n", ro)
quarto[[url_key]] <- regmatches(ro, m)[[1]][2]
# No output to read url from if quiet
if (isFALSE(quiet)) {
ro <- quarto[[ps_key]]$read_output()
cat(ro)

Check warning on line 122 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L120-L122

Added lines #L120 - L122 were not covered by tests
# Look at url to browse too in `quarto preview log`
if (
!isFALSE(browse) &&
is.null(quarto[[url_key]]) &&
grepl("Browse at https?://", ro)
) {
m <- regexec("Browse at (https?://[^ ]+)\n", ro)
quarto[[url_key]] <- regmatches(ro, m)[[1]][2]
}

Check warning on line 131 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L124-L131

Added lines #L124 - L131 were not covered by tests
}
if (!quarto[[ps_key]]$is_alive()) {
status <- quarto[[ps_key]]$get_exit_status()
quarto[[ps_key]] <- NULL
if (status != 0) {
stop("Error running quarto ", command)
cli::cli_abort(c(
x = "Error running {.code quarto {command}}.",
quiet_msg_suffix
))

Check warning on line 140 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L137-L140

Added lines #L137 - L140 were not covered by tests
}
return()
}
Expand All @@ -129,7 +146,13 @@
poll_process()

# indicate server is running
cat(paste0("Stop the preview with quarto_", command, "_stop()"))
if (isFALSE(quiet)) {
cli::cli
cli::cli_inform(c(
"",
i = "Stop the preview with {.code quarto_{command}_stop()}"
))

Check warning on line 154 in R/daemon.R

View check run for this annotation

Codecov / codecov/patch

R/daemon.R#L149-L154

Added lines #L149 - L154 were not covered by tests
}

# run the preview browser
if (!isFALSE(browse)) {
Expand Down
8 changes: 6 additions & 2 deletions R/preview.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#' @param watch Watch for changes and automatically reload browser.
#' @param navigate Automatically navigate the preview browser to the most
#' recently rendered document.
#' @param quiet Suppress warning and other messages, from R and also Quarto CLI
#' (i.e `--quiet` is passed as command line)
#'
#' @importFrom processx process
#' @importFrom rstudioapi isAvailable
Expand Down Expand Up @@ -52,7 +54,8 @@
host = "127.0.0.1",
browse = TRUE,
watch = TRUE,
navigate = TRUE
navigate = TRUE,
quiet = FALSE
) {
# default for file
if (is.null(file)) {
Expand All @@ -77,7 +80,8 @@
render,
port,
host,
browse
browse,
quiet = quiet

Check warning on line 84 in R/preview.R

View check run for this annotation

Codecov / codecov/patch

R/preview.R#L83-L84

Added lines #L83 - L84 were not covered by tests
)
}

Expand Down
6 changes: 5 additions & 1 deletion man/quarto_preview.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.