Extend prompt patterns to match more default irb prompts in recent ruby, jruby, and under rvm #6

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@purcell
purcell commented Mar 30, 2012

The following are examples of supported prompts:

1.9.3p125 :001 >
irb(main):001:0>
1.8.7 :001 >
1.9.3p125 :001 >
1.9.3-p125 :001 >
1.9.3-p125 :001 *
1.9.3-p125 :001 '
1.9.3-p125 :001 "
1.9.3-p125 :001 /
1.9.3-p125 :001 ]
1.9.3-p125 :001 `
jruby-1.6.7 :001 >

Rinari has long overridden inf-ruby-prompt-pattern, but it would
seem to make sense to improve the pattern at source, hence this pull
request.

There seems to be no technical reason for the previous difference
between inf-ruby-first-prompt-pattern and inf-ruby-prompt-pattern
-- this commit uses the same value for each, and IMO it would be worth
unifying the variables.

See eschulte/rinari#26 for related discussion.

purcell added some commits Mar 30, 2012
@purcell purcell Ignore .elc file 86a3d83
@purcell purcell Extend prompt patterns to match more default irb prompts in recent ru…
…by, jruby, and under rvm

The following are examples of supported prompts:

```
1.9.3p125 :001 >
irb(main):001:0>
1.8.7 :001 >
1.9.3p125 :001 >
1.9.3-p125 :001 >
1.9.3-p125 :001 *
1.9.3-p125 :001 '
1.9.3-p125 :001 "
1.9.3-p125 :001 /
1.9.3-p125 :001 ]
1.9.3-p125 :001 `
jruby-1.6.7 :001 >
```

Rinari has long overridden `inf-ruby-prompt-pattern`, but it would
seem to make sense to improve the pattern at source, hence this pull
request.

There seems to be no technical reason for the previous difference
between `inf-ruby-first-prompt-pattern` and `inf-ruby-prompt-pattern`
-- this commit uses the same value for each, and IMO it would be worth
unifying the variables.

See eschulte/rinari#26 for related discussion.
f7273be
@purcell
purcell commented Apr 3, 2012

The differences seem to appear principally under rvm, but there are still prompts described in the irb section of the original pickaxe book which were not matched by the original pattern. Note also that the "irb" part actually comes from the expansion of "command name", so it may vary if, say, irb is called jirb, or if an irb shell is spawned from a top-level program with a different name.

-Steve

@purcell
purcell commented Apr 3, 2012

To clarify, the proposed regexp doesn't handle such non-standard naming of irb, but I just wanted to mention it.

@nonsequitur
Owner

The prompt falls back to the default format when IRB is launched with the '--inf-ruby-mode' argument. (Which is assumed by inf-ruby-mode.)

Wouldn't this elegantly solve all the prompt detection issues?

@nonsequitur
Owner

If it's important to spot the Ruby version at a glance, we could easily add an option to inf-rb-mode for showing the current RUBY_DESCRIPTION in the buffer mode line.

@purcell
purcell commented Apr 3, 2012

Yeah; the need for a different regexp really grew from rinari, which uses rails console as the inferior ruby program, and there's no obvious way to pass irb args to that command. For my purposes, it's enough for rinari to handle these less-standard prompts, and I've patched it accordingly, but I guess it wouldn't be unreasonable for non-rinari users to use inf-ruby with rails console directly.

@dgutov
Collaborator
dgutov commented May 11, 2013

I'd also like to support pry prompts. It's orthogonal to using Rails and RVM, and it's sometimes used instead of IRB automatically: sickill/racksh#8

Example prompts:

[3] pry(main)>
[1] pry(#<Stringer>)>
@dgutov dgutov added a commit that closed this pull request Jun 2, 2013
@dgutov dgutov Handle different prompts, not just the IRB default
* The regexp is adapted from Rinari.
* Fixes #6.
a85ae01
@dgutov dgutov closed this in a85ae01 Jun 2, 2013
@dgutov
Collaborator
dgutov commented Jun 2, 2013

@purcell I've installed a modified version of the current Rinari prompt regexp.

There are still two regexps, in order for inf-ruby-get-old-input to return the full input, with newlines, in case of multiline input. IOW, if you type 1 +, press return, type 2, press return to send it, you can return to the point after 2 and press return again to make inf-ruby send the whole expression again, not just the last line.

I've simplified the regexp in a couple of places, so please be on the lookout for any breakage relative to Rinari.

@purcell
purcell commented Jun 3, 2013

Cool! I've disabled rinari's override, so let's see if anyone reports an issue:

eschulte/rinari@757cef2

FWIW, it looks like these were the test prompts I was using:

    1.9.3p125 :001 >
    irb(main):001:0>
    1.8.7 :001 >
    1.9.3p125 :001 >
    1.9.3-p125 :001 >
    1.9.3-p125 :001 *
    1.9.3-p125 :001 '
    1.9.3-p125 :001 "
    1.9.3-p125 :001 /
    1.9.3-p125 :001 ]
    1.9.3-p125 :001 `
    jruby-1.6.7 :001 >
@purcell
purcell commented Jun 3, 2013

In the end I removed rinari-inf-ruby-prompt-pattern altogether...

@dgutov
Collaborator
dgutov commented Jun 3, 2013

That makes sense. :)

Say, now that the prompts have moved here, what do you think about extracting the code responsible for rinari-console, to inf-ruby or some new package? At the bottom of dgutov/robe#3, there was an almost-feature-request asking for an easy way to launch consoles for different types of projects, which I think would be very good, but distinctly out of scope for Rinari.

@purcell
purcell commented Jun 4, 2013

Hmm, I don't know. There's not much code currently in rinari-console; it already delegates everything it can to inf-ruby.

@dgutov
Collaborator
dgutov commented Jun 5, 2013

I see. I didn't look at it before, and assumed that it at least looks for Gemfile and conditionally prepends bundle exec, but Rails doesn't really need that.

@dgutov
Collaborator
dgutov commented Jun 11, 2013

@purcell I think you should also bump the inf-ruby dependency version to the yet-unreleased 2.2.5. For when Rinari finally gets updated on Marmalade, that is.

@purcell purcell added a commit to eschulte/rinari that referenced this pull request Jun 16, 2013
@purcell purcell Bump inf-ruby dependency to 2.2.5 3da718a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment