Skip to content

Add rprompt support for right-side prompt display (take 2)#879

Merged
tompng merged 3 commits intoruby:masterfrom
amatsuda:rprompt_kwarg
Feb 3, 2026
Merged

Add rprompt support for right-side prompt display (take 2)#879
tompng merged 3 commits intoruby:masterfrom
amatsuda:rprompt_kwarg

Conversation

@amatsuda
Copy link
Member

Here's another take for the RPROMPT feature that I sent at #878.

Based on a discussion with @tompng, I changed the API from the Reline.rprompt= setter to a keyword argument for Reline.readline / Reline.readmultiline.
Added was a keyword argument rprompt:, plus, prompt: and add_hist: for consistency, keeping the existing positional ones for compatibility.

Usage

Reline.readline("> ", rprompt: "[%H:%M]")  # Setting prompt via positional arg and rprompt via kwarg

or

Reline.readline(prompt: "> ", rprompt: "[%H:%M]")  # Setting both prompt and rprompt via kwarg

Testing

Try this. Now it's much simpler, obviously.

ruby -rreline -Ilib -e 'print Reline.readline("> ", rprompt: "[#{Dir.pwd}]")'

lib/reline.rb Outdated
Reline::DEFAULT_DIALOG_CONTEXT = Array.new # :nodoc:

def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
def readmultiline(_prompt = '', _add_hist = false, prompt: _prompt, add_hist: _add_hist, rprompt: nil, &confirm_multiline_termination)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this add_hist: be add_history:?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did so, and actually replaced all occurrences of add_hist to add_history, because I found that changing the kwarg name only to add_history and keeping positional arg name and ivar name be add_hist makes the code hard to read.

This adds support for displaying a right-aligned prompt (rprompt)
similar to zsh's RPROMPT feature. The rprompt is displayed at the
right edge of the terminal and automatically hides when the input
line gets too long.

Usage:
  Reline.readline("> ", rprompt: "[%H:%M]")

The rprompt is rendered as part of Reline's normal render cycle,
so it persists during line editing unlike workarounds using
pre_input_hook.
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! thank you!

@tompng tompng merged commit d32ed17 into ruby:master Feb 3, 2026
45 of 48 checks passed
@amatsuda amatsuda deleted the rprompt_kwarg branch February 3, 2026 15:55
@tompng tompng mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants