Project

General

Profile

Actions

Feature #3616

closed

IRB + readline incorrectly counts non-printing characters in prompt

Added by guns (Sung Pae) almost 14 years ago. Updated about 13 years ago.

Status:
Closed
Target version:
-
[ruby-core:31484]

Description

=begin
When setting a prompt for IRB that contains terminal control characters:

 IRB.conf[:PROMPT][:COLOR] = {
   :PROMPT_I => "\e[0;1;32m>>> \e[0m",
   ...
 }
 IRB.conf[:PROMPT_MODE] = :COLOR

IRB includes "\e[...m" in the prompt length calculation, causing readline
functions like beginning-of-line to move to the incorrect place on the line:

 >>> 012345678901234567890
                          ^ caret
 <Press \C-a>
 >>> 012345678901234567890
                  ^ caret

Fortunately, GNU Readline offers a couple of constants to mark that a string
should be non-printing:

 # readline.h

 /* Definitions available for use by readline clients. */
 #define RL_PROMPT_START_IGNORE	'\001'
 #define RL_PROMPT_END_IGNORE	'\002'

Bash handles this issue by mapping \[' and ]' to RL_PROMPT_START_IGNORE and
RL_PROMPT_END_IGNORE inside of `PS*' prompt variables. It would be nice to offer
the same feature in IRB, or simply to surround all terminal escape sequences in
the IRB prompt with RL_PROMPT_*_IGNORE.

Note that this bug does not occur with libedit.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0