Skip to content
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

More powerful data for Pry.config.prompt #545

Closed
apeiros opened this issue Apr 19, 2012 · 4 comments
Closed

More powerful data for Pry.config.prompt #545

apeiros opened this issue Apr 19, 2012 · 4 comments

Comments

@apeiros
Copy link

apeiros commented Apr 19, 2012

It would be nice if we had more information readily available in the proc to generate the prompt. In order to enable adding those information over time without breaking the API all the time while doing so, I'd suggest to pass a single Struct instead of N arguments.

Example, instead of:
Pry.config.prompt = proc { |obj, nest_level, _| "#{obj}:#{nest_level}> " }
use:
Pry.config.prompt = proc { |state| "#{state.object}:#{state.pry_nesting}> " }

A couple of useful information:

  • line (current session)
  • historical_line (including the history)
  • continuation_type (what is open in a multiline)
  • continuation_indicator (same as above, but a standard indicator, e.g. " for open dquote string, ' for open squote string, / for regex, * for control-statements like if/case/begin/def/class/…, { for blocks, etc.)
  • pry_nesting (same as current 2nd arg)
  • pry (same as current 3rd arg)
  • object (same as current 1st arg)
@apeiros
Copy link
Author

apeiros commented Apr 19, 2012

Small amendment…
This can even be done in a backwards compatible way, leveraging to_ary:

PromptData = Struct.new(:object, :pry_nesting_level, :pry, …) do
  def to_ary
    warn "The use of multiple arguments in the prompt-proc is deprecated, please read …link…"
    [object, pry_nesting_level, pry]
  end
end

@banister
Copy link
Member

+1, this is great approach to clean up our unwieldy config apis

@yorickpeterse
Copy link
Contributor

Sounds good to me :)

@banister
Copy link
Member

banister commented Jul 9, 2012

done on my local HEAD, pushing soon

@banister banister closed this as completed Jul 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants