Add rprompt support for right-side prompt display#878
Closed
amatsuda wants to merge 1 commit intoruby:masterfrom
Closed
Add rprompt support for right-side prompt display#878amatsuda wants to merge 1 commit intoruby:masterfrom
amatsuda wants to merge 1 commit intoruby:masterfrom
Conversation
tompng
reviewed
Jan 17, 2026
| content_end = first_line.sum { |_, width, _| width } | ||
| # Only show rprompt if there's at least 1 char gap between content and rprompt | ||
| if right_col > content_end | ||
| first_line << [right_col, rprompt_width, @rprompt] |
Member
There was a problem hiding this comment.
This part adds segment of rpromt to new_lines[idx][2]. This part is OK, but segments added by dialog is now problematic.
Can you also change the dialog segment adding part?
# index 0 is for prompt, index 1 is for line, index 2.. is for dialog
dialog_rows[index + 2] = [x_range.begin, dialog.width, dialog.contents[row - y_range.begin]]index 2 is now used for rpromt, so dialogs should use index 3..
This is a current restriction of differential calculation assumption: same index represents logically same thing. Sorry for the inconvenience of this restriction.
Member
Author
There was a problem hiding this comment.
TBH I'm still not confident if I'm doing it right, but anyway I just updated 2 in the code to 3 without understanding anything...
Now this oneliner
ruby -I lib -r reline -e 'Reline.rprompt = "[#{Dir.pwd}]"; Reline.add_dialog_proc(:d, -> { Reline::DialogRenderInfo.new(pos: cursor_pos, contents: %w[A B C]) }); Reline.readline("prompt> ")'
creates this new_lines during render:
[[[0, 8, "prompt> "], [8, 0, ""], [168, 45, "[/Users/a_matsuda/src/github.com/ruby/reline]"]], [nil, nil, nil, nil, [8, 1, "\e[0mA"]], [nil, nil, nil, nil, [8, 1, "\e[0mB"]], [nil, nil, nil, nil, [8, 1, "\e[0mC"]]]
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.rprompt = "[%H:%M]"
Reline.readline("> ")
The rprompt is rendered as part of Reline's normal render cycle,
so it persists during line editing unlike workarounds using
pre_input_hook.
Member
|
Closing in favor of #879 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This patch adds support for displaying a right-aligned prompt (
rprompt) similar to zsh'sRPROMPTfeature.Usage
Implementation
rpromptattribute toReline::Core(reader + setter)rprompttoLineEditorininner_readlineLineEditor#render, add rprompt as a segment on the first visible line at[right_col, width, text]Motivation
I wanted to have this feature for my app that I'm building on top of Reline, and found it difficult to implement without patching Reline itself.
Testing
Behavior of the RPROMPT feature can be confirmed with something like this.