From: Sung Pae Date: 2010-07-26T14:56:14+09:00 Subject: [ruby-core:31484] [Bug #3616] IRB + readline incorrectly counts non-printing characters in prompt Bug #3616: IRB + readline incorrectly counts non-printing characters in prompt http://redmine.ruby-lang.org/issues/show/3616 Author: Sung Pae Status: Open, Priority: Normal ruby -v: ruby 1.9.2dev (2010-07-24 revision 28749) [x86_64-darwin10.4.0] 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 >>> 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. ---------------------------------------- http://redmine.ruby-lang.org