Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANSI colors in prompt string #150

Closed
aleclarson opened this issue Feb 14, 2018 · 4 comments
Closed

ANSI colors in prompt string #150

aleclarson opened this issue Feb 14, 2018 · 4 comments

Comments

@aleclarson
Copy link

aleclarson commented Feb 14, 2018

I'm using https://github.com/hoelzro/lua-linenoise and noticed that the prompt string cannot contain non-printed characters without messing up tab completion, which must be due to incorrect string length calculation. My use case is ANSI coloring (256 spectrum).

hoelzro/lua-linenoise#15

@hoelzro
Copy link
Contributor

hoelzro commented Feb 15, 2018

It's worth mentioning that readline gets around this by using \001 and \002 and "non-printable" markers: see rl_expand_prompt under https://tiswww.case.edu/php/chet/readline/readline.html

@aleclarson
Copy link
Author

aleclarson commented Feb 21, 2018

Semi-duplicate of #25

@hoelzro
Copy link
Contributor

hoelzro commented Feb 21, 2018

@aleclarson I would re-open this - I don't consider this a duplicate of #25.

On a side note: what GNU readline does for this is uses \001 and \002 to mark the parts of the string that shouldn't contribute to the prompt length: https://wiki.hackzine.org/development/misc/readline-color-prompt.html

@Sonophoto
Copy link

@hoelzro @aleclarson

This is in fact an explicitly stated sub issue of #25 and I encourage you to read the discussion in full. Linenoise code isn't as abstracted as GNU Readline, that is by design.

This version of linenoise has multibyte and ANSI color Right Now in C++, and works on windows too.

https://github.com/yhirose/cpp-linenoise

If you need to use multibyte and ANSI in C then this one will work:
(Notice: It has several other modifications: master...Sonophoto:master

https://github.com/Sonophoto/linenoise/blob/master/linenoise.c

ANSI color was an issue for me early on and that issue is resolved by the discussion in #25 and the corrected UTF-8 character counting implemented by @yhirose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants