API

Replay.replay — Function
replay(instructions::Vector{<:AbstractString}, buf::IO; kwargs...)

Replay the REPL output from given instructions.

Each element of instructions is one complete input submitted to the REPL. Multi-line inputs such as a function ... end definition must stay in a single element. An instruction that the parser reports as incomplete raises an ArgumentError before the child REPL is started. To replay a whole script, pass it as a single string; see the replay(script::AbstractString) method.

Keyword Arguments

Replay options

  • use_ghostwriter: Flag to enable ghostwriter mode. (default: false)

  • startup_prompt: Text to wait for when the child REPL starts. (default: "julia>")

  • prompt_delimiter: Text ending each subsequent prompt. (default: "> ") For numbered prompts use startup_prompt="In [1]: ", prompt_delimiter="]: ", and leave use_ghostwriter=false; ghostwriter assumes the standard prompts.

Julia options

  • julia_project: Path to a project where julia process runs. (default: @.)
  • cmd: Additional command for julia process. (default: "--color=yes")

Numbered prompts

Initialize Julia's REPL interface before enabling numbered prompts:

replay(["1 + 1", "ans * 2"];
    cmd=`-q --color=no -e 'using REPL; atreplinit(repl -> (repl.interface = REPL.setup_interface(repl); REPL.numbered_prompt!(repl)))'`,
    startup_prompt="In [1]: ", prompt_delimiter="]: ")

Interactive menus

ASCII REPL.TerminalMenus menus can be replayed with the default prompt delimiter. Put the request and its response in separate instructions and use a carriage return ("\r") to confirm a selection:

replay([
    "using REPL.TerminalMenus",
    "menu = RadioMenu(["apple", "orange"]);",
    "choice = request("Choose fruit:", menu)",
    "$(DOWN_ARROW)\r",
    "@show choice",
])

Use "q" to cancel a TerminalMenus request. Menu requests must display the configured prompt_delimiter; arbitrary full-screen TUIs or menus with different cursor styles are not automatically detected. Keep use_ghostwriter=false for raw menu keystrokes.

source
Replay.replay — Method
replay(script::AbstractString, buf::IO=stdout; kwargs...)

Split script into REPL inputs and replay them.

Splitting uses the REPL's own completeness rule: lines are accumulated until Base.parse_input_line no longer returns an Expr(:incomplete), so a multi-line definition is submitted as one input. Lines that start with ;, ] or ? at column 0 are treated as shell, pkg and help mode commands, and a line starting with a Ctrl-C character interrupts the current mode.

The script must be complete. If it ends in the middle of an expression, an ArgumentError is raised instead of leaving the child REPL waiting for input.

source
Replay.@deparse — Macro
@deparse expr

Return expr as a Julia source string using Julia's own printer, i.e. string(expr). LineNumberNodes are removed first, so the result contains no #= file:line =# markers.

The macro does not try to reproduce the exact whitespace or syntax you typed; it returns Julia's canonical representation of the parsed expression.

Examples

julia> @deparse 1+1
"1 + 1"

julia> @deparse sin(1f0+a)
"sin(1.0f0 + a)"

julia> @deparse f(x) = sin(x)/x
"f(x) = begin\n        sin(x) / x\n    end"
source