A reimplementation of the Rust Playground

Repository

I'll be writing a blog post about my experiences in creating this, and if anyone has any questions, please let me know and I'll attempt to address them!

A direct link to the playground for us lazy programmers.

2 Likes

In the Playground I'd like:

  • A button to show just the source code of the paste in raw format. This is very useful to copy&paste code, especially when I'm on a mobile device;
  • A button to run Clippy (with default configuration) on the source code.
4 Likes

Any chance of enabling external crates? That's probably the biggest limitation of the exiting playground IMO.

Without networking in your container, I guess you'd have pre-fetch all the crate sources, then maybe a .cargo/config can point to them.

2 Likes

^^ THIS! I disable the javascript clipboard API because I don't like websites messing with my clipboard but that unfortunately makes the playground very hard to use.

I'd also like the equivalent of "cargo check". Just tell me if it compiles or not, but I don't need to actually run the code.

+1 for cargo check

Enhancement request created: Add option to run Clippy · Issue #5 · rust-lang/rust-playground · GitHub

Enhancement request created: Support a whitelist of crates ... somehow · Issue #4 · rust-lang/rust-playground · GitHub

@leonardo, @stebalien Could you help me understand the goal here a bit more? Are you saying that copying the source code from the editor is difficult on mobile? That I could believe, but why wouldn't you want to create a gist to more easily share the code? I'm unclear why the JS clipboard API comes into play here.

@jethrogb, @mfcastellani what's the main concern driving this? Is it mostly based around request time? If so, is it because the code generation is slow, or is the execution of the program slow?

The usage pattern is simple. If somewhere I see a link to a Playground snippet, I can open the page, click on the "Show raw" button, copy the whole page, and paste it locally to do anything with the code. This is fast to do, while copying the code from the normal Playground windows is a little more laborious, especially on mobile. This site has a "raw code" link like that (you need an actual paste to see the link):

http://codepad.org/

But this is not an essential feature, I can live without it. Having a Clippy button is probably more important.

I think @leonardo and I have having different problems. There is no (sane) way to copy text out of the editor without enabling the clipboard API. The text selection you're seeing is faked in javascript (real text selection is disabled by some CSS).

Ah, I see now that copying is some trickery from the Ace Editor. Amusingly, pasting is OK because there's a tiny text area that you actually enter into. I might just roll this into another "output" pane, but without a need to click a button. Then you can just select the text within.

@stebalien @leonardo what would be easiest: a div/pre or a textarea with the raw code?

Personally, a pre with the text preselected would be best.

textarea would have the advantage of allowing editing the code rather than just copying it. At least on iOS, text selection doesn't work at all with Ace, real or fake, and even tapping to move around the editor doesn't work properly (it's subject to the 350ms delay and flashes the whole editor grey for a moment).

It looks like fixing this would solve everyones issues:
https://github.com/rust-lang/rust-playpen/issues/198

Ah, that has a nice accessibility benefit, and hopefully helps out you, @leonardo and @comex. This is now live; there's a "editor style" option in the brand new "config" button. Check it out :slight_smile: