New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fancier multiline support for `wp shell` #316

Closed
scribu opened this Issue Feb 21, 2013 · 4 comments

Comments

2 participants
@scribu
Copy link
Member

scribu commented Feb 21, 2013

I just came accross a very neat feature in the CoffeeScript REPL:

coffee>

Press Ctrl+V.

------>

And now you can enter multiple lines of input, which will get evaluated only when you press Ctrl+V again.

Given the limited meta-programming abilities in PHP, I think this approach would make the most sense for the WP shell.

PS: CoffeeScript also supports adding a \ at the end of input, to avoid immediate evaluation.

@nb

This comment has been minimized.

Copy link
Contributor

nb commented Apr 30, 2013

While Ctrl+V would definitely work, it’s one shortcut too many :-)

In most of the cases when I want multi-line input, I am trying to execute a single, but multi-line statement: a function, a foreach loop, an if, a class, even. Ideally, I would like to be able to finish my statement, before the shell tries to execute it.

A few options:

  • Expect more input input while we have unclosed delimiters ((/), {/}, if/endif, foreach/endforeach, etc.), evaluate only if everything is closed.
  • Be even smarter: detect parse errors in the middle lines and thus prevent users from writing something long, which has a parse error in the second line. Python does that. This is a bit trickier, but the PHP parser is our friend.
@scribu

This comment has been minimized.

Copy link
Member Author

scribu commented Apr 30, 2013

Yes, I know Python does that; that's why I quit my PHP job. :P

Personally, I'm not going to bother trying to match delimiters or mess with the PHP parser. If someone does tackle this, they should package it up as a generic library, since I'm sure many people would find it useful in their own PHP REPLs.

Related: #292

@scribu

This comment has been minimized.

Copy link
Member Author

scribu commented May 5, 2013

It seems someone has already gone through the pain of wading through PHP tokens to provide multiline support. It's an abandoned project called php-shell:

The multiline part is used in the WordPress Console plugin:

https://github.com/jerodsanto/wordpress-console/blob/v0.3.9/common.php#L78-633

@nb

This comment has been minimized.

Copy link
Contributor

nb commented May 6, 2013

Wow.

scribu pushed a commit that referenced this issue May 8, 2013

Cristi Burcă
Merge pull request #437 from wp-cli/boris
Use Boris to power `wp shell`

fixes #292 and #316

@scribu scribu closed this May 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment