Skip to main content

Module record

Module record 

Source
Expand description

The dayscript recorder and in-process playback (§14.6): capture the events an app receives back into a replayable dayscript, and replay one against the live UI. See record::start/record::play. The dayscript recorder (DESIGN.md §14.6): the inverse of playback. Where the engine turns a script into synthesized Day events, the recorder turns the events an app receives back into a script. It hooks one point, day_core::set_event_observer, which every backend funnels its native events through (day_core::enqueue_events), so it needs no per-toolkit code, and it emits an ordinary dayscript that replays cross-toolkit through the same executor as any hand-written one.

Scope is narrow: actions only, and only where the step is portable. A tap, a text edit, a selection/toggle, a navigation, a back: the id-addressed things a walkthrough is made of. Positional taps, gestures, slider drags, and native OS chrome are dropped (see event_to_step); the resulting script is a starting point to edit, not a pixel-exact replay.

Everything here is main-thread state (the observer only ever runs on the main thread, where day-core dispatches). On wasm there is no in-process playback (play); the WebSocket transport drives the page instead (docs/web.md).

Functions§

annotate_yaml
Like steps_to_yaml, but each step’s identifying line carries a trailing # "label" comment naming the control it came from (§14.6): its accessibility label, or its visible text. The comment sits on the id: line for a tap/input/select and the route: line for a navigate, so a reader sees route: focus # "Focus". Comments are ordinary YAML, so an annotated script parses and replays exactly as the bare one does; this is the form the recorder streams and saves.
clear
Discard the recorded steps (recording, if live, continues from empty). Mirrors the emptied script into any live sink.
exclude_prefix
Skip events whose element id starts with prefix: set it to the id prefix an app gives its record/stop/play controls so they never record themselves. Set before start*.
is_logging_actions
Whether log_actions is on.
is_paused
Whether a live run is suspended.
is_playable
Whether yaml is a non-empty, parseable script, which a Play button binds its enabled state to.
is_playing
Whether a script is playing right now; paused counts as playing.
is_recording
Whether a recording is currently live.
log_actions
Log every action the app receives to stdout, in the recorder’s vocabulary, the same lines a recording echoes, minus the recording:
pause_playback
Suspend the running script between steps. The step in flight finishes, because a step is one synthesized action dispatched to the main thread, and abandoning it mid-flight would leave the UI in a state no script describes.
paused_signal
The reactive “playback is paused” flag. Only meaningful while playing_signal is set.
play
Play a dayscript in-process (§14.6): parse yaml and run each step through the same executor the socket runner uses (crate::run_step_with_wait), on a spawned thread that dispatches each step to the main thread and awaits its reply, mirroring the engine’s connection loop. Returns as soon as the run is dispatched (the steps then run asynchronously against the live UI). Refuses while a recording is live, so a replay never records itself.
play_with_delay
Play with an artificial pause (seconds) between each step: a slow-motion replay for watching a script drive the UI. Returns Err without spawning when the script is empty or does not parse, so a UI can call it to validate (see is_playable) and to run from one path.
playback_supported
Whether in-process playback exists on this target: false on wasm, which has no background thread to drive the steps from (drive the page over the dayscript WebSocket transport there, docs/web.md).
playing_signal
The reactive “a script is playing” flag, which a Play/Pause button binds its icon to.
recording_signal
The reactive recording flag: true while recording. Bind a control’s label/style to it (the showcase’s Record↔Stop button does). The same global handle every call, so reads from any page track the one signal.
resume_playback
Resume a paused run.
save
Write the recorded script to path.
script
The recorded script as canonical dayscript YAML (steps_to_yaml); flow: [] when empty.
start
Start recording into memory only (read it back with script / steps / save).
start_into
Start recording, mirroring the script text into sig on every event: the streaming, editable buffer an app binds a text_area to. Called again while already recording, it re-targets the stream at sig (keeping the recording so far) rather than restarting, which is what a page needs after it was disposed and rebuilt mid-recording.
start_to_file
Start recording, continuously flushing the script to path; this is how DAY_RECORD / day launch --record capture headlessly. Crash-resilient: the file holds everything up to the last event even if the app is killed.
steps
The recorded steps, cloned.
steps_from_yaml
Read operations for in-process playback. Host annotations and failure policy are validated but execution remains the caller’s responsibility.
steps_to_yaml
Serialize operations without host annotations, as the recorder does.
stop
Stop recording and remove the observer. The captured script is kept (read it with script / steps / save, or resume with a start*).
stop_playback
Abandon the run: the replay thread stops before its next step (immediately if it is paused). The steps already played are not undone; there is nothing to undo them with.
version
A counter that increments each time a step is recorded (or the recording is cleared). A UI can watch it to react to recording progress (a live step count, say) without owning the mirrored buffer signal. Global-scoped, so it survives page rebuilds.