0

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.

lcmylin
  • 2,552
  • 2
  • 19
  • 31
  • 1
    I cannot reproduce your issue. I don't have a Gnome Terminal immediately at my fingertips, but I tested in an XTerm, in a KDE Konsole, and in a non-graphical Linux session, and in every case, the prompt emitted by `readline("\x1b[34m" "prompt>" "\x1b[m");` was colored blue, and the visible text was only "prompt>". The appearance was identical to what I got by printing the same string with `puts()`. Perhaps a [mcve] would help. – John Bollinger May 10 '19 at 20:27
  • a lot depends on the `termcap` file and the actual terminal you are using. – user3629249 May 10 '19 at 21:55

1 Answers1

0

I might never know what was going wrong. I had fully cleaned the build on my project multiple times while testing this (regenerating whole CMake build tree, etc.), but simply deleting and re-downloading my own repo has fixed this.

lcmylin
  • 2,552
  • 2
  • 19
  • 31