Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured reference index #60

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -45,4 +45,4 @@ Config/Needs/website: r-lib/downlit, tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2.9000
16 changes: 8 additions & 8 deletions R/errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ err <- local({
#' @param ... Parts of the error message, they will be converted to
#' character and then concatenated, like in [stop()].
#' @param call. A call object to include in the condition, or `TRUE`
#' or `NULL`, meaning that [throw()] should add a call object
#' or `NULL`, meaning that `throw()` should add a call object
#' automatically. If `FALSE`, then no call is added.
#' @param srcref Alternative source reference object to use instead of
#' the one of `call.`.
Expand All @@ -191,10 +191,10 @@ err <- local({
#' It also adds the `rlib_error` class.
#'
#' @noRd
#' @param ... Passed to [new_cond()].
#' @param call. Passed to [new_cond()].
#' @param srcref Passed tp [new_cond()].
#' @param domain Passed to [new_cond()].
#' @param ... Passed to `new_cond()`.
#' @param call. Passed to `new_cond()`.
#' @param srcref Passed to `new_cond()`.
#' @param domain Passed to `new_cond()`.
#' @return Error condition object with classes `rlib_error`, `error`
#' and `condition`.

Expand Down Expand Up @@ -326,7 +326,7 @@ err <- local({
#' @noRd
#' @param expr Expression to evaluate.
#' @param err Error object or message to use for the child error.
#' @param call Call to use in the re-thrown error. See [throw()].
#' @param call Call to use in the re-thrown error. See `throw()`.

chain_error <- function(expr, err, call = sys.call(-1), srcref = NULL) {
.hide_from_trace <- 1
Expand Down Expand Up @@ -386,7 +386,7 @@ err <- local({

#' Version of entrace_call that supports cleancall
#'
#' This function is the same as [entrace_call()], except that it
#' This function is the same as `entrace_call()`, except that it
#' uses cleancall's [.Call()] wrapper, to enable resource cleanup.
#' See https://github.com/r-lib/cleancall#readme for more about
#' resource cleanup.
Expand Down Expand Up @@ -421,7 +421,7 @@ err <- local({

#' Create a traceback
#'
#' [throw()] calls this function automatically if an error is not caught,
#' `throw()` calls this function automatically if an error is not caught,
#' so there is currently not much use to call it directly.
#'
#' @param cond Condition to add the trace to
Expand Down
84 changes: 42 additions & 42 deletions R/merge.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
new_merge_cast_command <- function(command, output) {
structure(
list(command = command, output = list(output = output)),
class = "merge_cast_command"
)
}

#' @rdname merge_casts
#' @export

clear_screen <- function() {
output <- tibble::tibble(
time = 0,
type = "o",
data = "\u001b[H\u001b[2J"
)
new_merge_cast_command("clear_screen", output = output)
}

#' @rdname merge_casts
#' @param secs Number of seconds to wait.
#' @export

pause <- function(secs) {
output <- tibble::tibble(
time = as.numeric(secs),
type = "o",
data = ""
)
new_merge_cast_command("pause", output = output)
}

handle_merge_cast <- function(x) {
if (inherits(x, "merge_cast_command")) {
list(type = "command", output = x$output)
} else if (inherits(x, "asciicast")) {
list(type = "cast", output = x)
} else {
list(type = "cast", output = read_cast(x))
}
}

#' Merge multiple ASCII casts into one
#'
#' The new cast will inherit its options (screen size, etc.) from the
Expand Down Expand Up @@ -77,6 +35,16 @@ merge_casts <- function(...) {
)
}

handle_merge_cast <- function(x) {
if (inherits(x, "merge_cast_command")) {
list(type = "command", output = x$output)
} else if (inherits(x, "asciicast")) {
list(type = "cast", output = x)
} else {
list(type = "cast", output = read_cast(x))
}
}

shift_output <- function(recs) {
last <- map_dbl(recs, function(x) utils::tail(x$time, 1)) + 1 / 10000
shift <- utils::head(cumsum(c(0, last)), -1)
Expand All @@ -85,3 +53,35 @@ shift_output <- function(recs) {
}
do.call(rbind, recs)
}

#' @rdname merge_casts
#' @export

clear_screen <- function() {
output <- tibble::tibble(
time = 0,
type = "o",
data = "\u001b[H\u001b[2J"
)
new_merge_cast_command("clear_screen", output = output)
}

#' @rdname merge_casts
#' @param secs Number of seconds to wait.
#' @export

pause <- function(secs) {
output <- tibble::tibble(
time = as.numeric(secs),
type = "o",
data = ""
)
new_merge_cast_command("pause", output = output)
}

new_merge_cast_command <- function(command, output) {
structure(
list(command = command, output = list(output = output)),
class = "merge_cast_command"
)
}
34 changes: 34 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,39 @@ template:
in_header: |
<script defer data-domain="/asciicast.r-lib.org,all.tidyverse.org" src="https://plausible.io/js/plausible.js"></script>

reference:
- title: Basics
contents:

- title: Basics
contents:
- record
- play
- merge_casts
- record_output

- title: Sharing
contents:
- write_svg
- write_html
- write_gif
- write_json
- read_cast

- title: Theming and options
contents:
- default_theme
- asciicast_options
- '`asciicast-package`'

- title: Other functions
contents:
- get_locales
- init_knitr_engine
- asciicast_start_process
- asciinema_player
- expect_snapshot_r_process
- install_phantomjs

development:
mode: auto
1 change: 1 addition & 0 deletions asciicast.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 6d3a84a0-b1f6-4617-b66c-a4cd26058153

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
2 changes: 1 addition & 1 deletion man/asciicast_start_process.Rd

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

2 changes: 1 addition & 1 deletion man/asciinema_player.Rd

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

2 changes: 1 addition & 1 deletion man/default_theme.Rd

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

2 changes: 1 addition & 1 deletion man/expect_snapshot_r_process.Rd

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

14 changes: 7 additions & 7 deletions man/merge_casts.Rd

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

2 changes: 1 addition & 1 deletion man/play.Rd

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

4 changes: 2 additions & 2 deletions man/read_cast.Rd

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

2 changes: 1 addition & 1 deletion man/record.Rd

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

2 changes: 1 addition & 1 deletion man/write_json.Rd

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

2 changes: 1 addition & 1 deletion man/write_svg.Rd

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

Loading