Author mic_e
Recipients ezio.melotti, mic_e
Date 2013-03-02.16:00:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The issue might very well be strictly related to GNU readline.

I have both successfully reproduced it in a C program:

#include <stdio.h>
#include <readline/readline.h>
int main() {
        readline("\x1b[31;1mthis is a bold red prompt\x1b[m> ");

gcc -lreadline test.c

and found a fix, hinted at by this stackoverflow post:

Readline uses the characters \x01 and \x02 to mark invisible portions of the prompt, so I am now pre-processing the prompt with this function:

def surround_ansi_escapes(prompt, start = "\x01", end = "\x02"):
        escaped = False
        result = ""

        for c in prompt:
                if c == "\x1b" and not escaped:
                        result += start + c
                        escaped = True
                elif c.isalpha() and escaped:
                        result += c + end
                        escaped = False
                        result += c

        return result

However, in my opionion this fact deserves at least to be mentioned in the readline documentation.
Date User Action Args
2013-03-02 16:00:01mic_esetrecipients: + mic_e, ezio.melotti
2013-03-02 16:00:01mic_esetmessageid: <>
2013-03-02 16:00:01mic_elinkissue17337 messages
2013-03-02 16:00:00mic_ecreate