Replay.jl icon indicating copy to clipboard operation
Replay.jl copied to clipboard

Replay interactive REPL menus?

Open gdalle opened this issue 1 year ago • 3 comments

Hi there, thanks for the awesome package! I'm writing a blog post on Julia workflows, and I want to demonstrate the use of packages like Cthulhu, PkgTemplates and others which have interactive terminal menus. Is that something Replay can help with? Or does it only work with plain REPL prompts?

gdalle avatar Jul 06 '23 06:07 gdalle

Hello, @gdalle

My apologies for the delay.

I'm writing a blog post on Julia workflows, and I want to demonstrate the use of packages like Cthulhu, PkgTemplates and others which have interactive terminal menus.

This is cool 👍. If your instruction is self-contained within Julia REPL, Replay.jl can help you. For example here I used Replay.jl to show how to use Debugger.jl

https://github.com/AtelierArith/julia_tutorial/blob/main/demos/06_debugger/script.jl

$ cd /path/to/06_debugger/script.jl
$ julia --project=@. -e 'using Pkg; Pkg.instantiate()'
$ julia --project=@. script.jl

https://github.com/AtelierArith/Replay.jl/assets/16760547/91d5f15d-a01d-4c49-8238-4a0b1aa60db5

The following example shows how to use Revise.jl. Have a try 🚀

https://github.com/AtelierArith/julia_tutorial/blob/main/demos/05_revise/script.jl

terasakisatoshi avatar Sep 05 '23 15:09 terasakisatoshi

Although this is not a beautiful solution (especially CTRL_M), it works.

using Replay

UP_ARROW = "\e[A"
DOWN_ARROW = "\e[B"
CTRL_M = "\x0D"

instructions = [
    "using REPL.TerminalMenus",
    """
    options = ["apple", "orange", "grape", "strawberry",
                "blueberry", "peach", "lemon", "lime"];
    """,
    "menu = RadioMenu(options, pagesize=4);",
    """
    choice = request("Choose your favorite fruit:", menu)
    """,
    "$(DOWN_ARROW)$(DOWN_ARROW)$(CTRL_M)",
]

replay(instructions)

terasakisatoshi avatar Sep 05 '23 16:09 terasakisatoshi

Thanks for the answer! I'll see where I can incorporate this

gdalle avatar Sep 06 '23 07:09 gdalle