Skip to content

Commit

Permalink
quarto_preview() now looks at quarto preview` log to browse to the …
Browse files Browse the repository at this point in the history
…correct url when inside RStudio viewer

closes #167
  • Loading branch information
cderv committed Jul 19, 2024
1 parent 7f44c13 commit 1473245
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# quarto (development version)

- `quarto_preview()` now looks at `quarto preview` log to browse to the correct url when inside RStudio viewer (thanks, @aronatkins, #167).

- This package now uses the x.y.z.dev versionning scheme to indicate development, patch, minor and major versions. This follows [Tidyverse package version conventions](https://r-pkgs.org/lifecycle.html#sec-lifecycle-version-number-tidyverse).

- Adapt tests for CRAN checks issues due to Quarto v1.5.54 regression, fixed in Quarto v1.5.55.
Expand All @@ -13,7 +15,7 @@
- Add registration of vignette engine to use `quarto` as a vignette builder, and use `.qmd` file as vignette. See `vignette("hello", package = "quarto")`. (thanks, @dcnorris, #57).

- New `quarto_binary_sitrep()` checks possible difference in Quarto binary used by this package, and the one used by RStudio IDE (thanks, @jthomasmock, #12).

- New `is_using_quarto()` to check if a directory requires using Quarto (i.e. it has a `_quarto.yml` or at least one `*.qmd` file) (thanks, @hadley, #103).

- New `quarto_create_project()` calls `quarto create project <type> <name>` (thanks, @maelle, #87).
Expand Down
17 changes: 15 additions & 2 deletions R/daemon.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
# calculate keys
ps_key <- paste0(command, "_ps")
port_key <- paste0(command, "_port")
url_key <- paste0(command, "_url")
# We don't need to keep previous url
quarto[[url_key]] <- NULL

# manage existing server instances
stop_serve_daemon(command)
# we don't need to keep previous url
quarto[[url_key]] <- NULL

# if the last server had a port then re-use it for "auto"
if (port == "auto") {
Expand Down Expand Up @@ -86,12 +91,20 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
}
quarto[[port_key]] <- port



# monitor the process for abnormal exit
poll_process <- function() {
if (is.null(quarto[[ps_key]])) {
return()
}
cat(quarto[[ps_key]]$read_output())
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
Expand All @@ -116,7 +129,7 @@ run_serve_daemon <- function(command, target, wd, extra_args, render, port, host
utils::browseURL
)
}
serve_url <- paste0("http://localhost:", port)
serve_url <- quarto[[url_key]] %||% paste0("http://localhost:", port)
browse(serve_url)
}

Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ merge_list <- function(x, y) {
x[names(y)] <- y
x
}

`%||%` <- function(x, y) {
if (is_null(x)) y else x
}

0 comments on commit 1473245

Please sign in to comment.