Cargo playground opens a local playground in the editor of your choice.
You can install it directly using cargo
$ cargo install --git https://github.com/Lutetium-Vanadium/cargo-playground
Or clone the project and then install
$ git clone https://github.com/Lutetium-Vanadium/cargo-playground
$ cd cargo-playground
$ cargo install --path .
cargo-playground
on crates.io was already registered to someone else as a dummy project, and is not this project. Please install only using the above methods.
A few examples:
# Create a new playground
$ cargo playground new -n test-playground rand
# List existing playgrounds
$ cargo playground ls
# Open an existing playground
$ cargo playground open -e vim -a=-o2 test-playground
The following environment variables are used:
-
VISUAL
: The editor in which to open the playground. It is required unless --editor is given -
CARGO_PLAYGROUND_DIR
: The path to the directory which is used for creating playgrounds. If not set, the temp directory is used. eg: in unix:/tmp/cargo-playground/
This creates and opens a new playground.
It has the following options and flags:
-g, --gui Indicates the editor is a GUI based
--no-w Do not pass -w flag when opening GUI editor
-n, --name <name> The name of the playground. By default it is
generated from the current timestamp
-e, --editor <editor> The editor to open the project in. By default
it is taken from the VISUAL env variable.
-a, --args <args>... Args to be given to be supplied to the editor.
-t, --template <template> A dependency to take examples from as a base
for main.rs. Same format as dependencies.
It also takes a list of dependencies in the following formats:
<dep-name>
eg:"rand"
<dep-name> = <dep-version>
eg:"rand = 0.7"
<dep-version>
should not have quotes
This opens a playground with the given name.
It has the following options and flags:
-g, --gui Indicates the editor is a GUI based
--no-w Do not pass -w flag when opening GUI editor
-e, --editor <editor> The editor to open the project in. By default it
is taken from the VISUAL env variable.
-a, --args <args>... Args to be given to be supplied to the editor.
This lists all the playgrounds.
Deletes the Cargo projects in the playground directory.
It has the following options:
-m, --matches <matches> A regex to match against playground names. If
not given all will be deleted.
-
Terminal based editor + tmux: It opens a pane to the right which has the output process, and the editor will be open to the left. When the editor is closed, the playground will be closed.
-
GUI based editors: This requires the extra flag
-g/--gui
. It shows the output process in the main terminal and opens the editor.Any output from the editor to stdout/stdin will be ignored and not shown.
For example:
# Creates a new playground with vscode as editor $ cargo playground new -ge code # ^^^^^^-- not required if VISUAL is set to code
I have noticed that cli openers for gui programs exit instantly and require a
-w
flag to make it wait. As such opening with gui editors automatically supplies a-w
flag. In case your editor doesn't behave this way, use the--no-w
flag to disable it.
If you want to add specific for some editor or environment feel free to open a PR!