Skip to content

Conversation

@amatsuda
Copy link
Member

Summary

This patch 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
  • Automatically hides when the input line gets too long (prevents overlap)
  • Persists during line editing (backspace, Ctrl-U, etc.) because it's part of Reline's render cycle

Usage

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

Implementation

  • Added rprompt attribute to Reline::Core (reader + setter)
  • Pass rprompt to LineEditor in inner_readline
  • In LineEditor#render, add rprompt as a segment on the first visible line at [right_col, width, text]
  • Uses the same segment-based rendering as dialogs

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.

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

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.
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.

1 participant