I'm trying to use GNU Readline with a colored prompt. Boiled down to a minimal test case, my readline()
invocation looks like this:
readline("\x1b[34m" "prompt>" "\x1b[m");
I expected to see a prompt like this (just imagine it being blue):
prompt>
but instead I see:
[34mprompt>[m
I read about prompt expansion in the docs, and thought something weird might be happening there. But the expanded prompt is fine, and this works as expected:
rl_set_prompt("\x1b[34m" "prompt>" "\x1b[m");
printf("%s", rl_prompt); // Prints "prompt>" in blue
This happens both in Gnome Terminal and Xterm. I'm using libreadline 7 on Ubuntu 18.04. I can't for the life of me figure out what's going on here, and nobody online seems to be having this problem.