Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: quarto
Title: R Interface to 'Quarto' Markdown Publishing System
Version: 1.4.4.9006
Version: 1.4.4.9007
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-0174-9868")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# quarto (development version)

- `quarto_preview()` gains a `quiet` argument to suppress any output from R or Quarto CLI (thanks, @cwickham, #232.)

- Add some helpers function `theme_brand_*` and `theme_colors_*` to help theme with dark and light brand using some common graph and table packages (thanks, @gordonwoodhull, [#234](https://github.com/quarto-dev/quarto-r/issues/234)).

- Add `quarto.quiet` options to allow more verbose error message when `quarto_*` function are used inside other package.
Expand Down
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 @@ run_serve_daemon <- function(
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 @@ run_serve_daemon <- function(
} 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 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)
}

# command and target
Expand Down Expand Up @@ -75,6 +77,13 @@ run_serve_daemon <- function(
# 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."
}

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

Expand All @@ -92,10 +101,12 @@ run_serve_daemon <- function(
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())
}
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))
}
}
quarto[[port_key]] <- port
Expand All @@ -105,22 +116,28 @@ run_serve_daemon <- function(
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)
# 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]
}
}
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
))
}
return()
}
Expand All @@ -129,7 +146,13 @@ run_serve_daemon <- function(
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()}"
))
}

# 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 @@ quarto_preview <- function(
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 @@ quarto_preview <- function(
render,
port,
host,
browse
browse,
quiet = quiet
)
}

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.