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

Bug: Cursor moves far to the right if prompt has colors #158

Open
mckenney5 opened this issue Aug 6, 2018 · 2 comments
Open

Bug: Cursor moves far to the right if prompt has colors #158

mckenney5 opened this issue Aug 6, 2018 · 2 comments

Comments

@mckenney5
Copy link

mckenney5 commented Aug 6, 2018

If the prompt contains a color code, the cursor moves far to the right.
This is probably due to the fact that plen would include each char in the color code even though they have no bearing on cursor position (since they aren't printed to the screen like a char).

This is reproduce-able with this modified code:
#ifndef NO_COLOR

#define RED "\x1B[31m"

#define WHITE "\x1B[37m"

#define RESET "\x1B[0m"

#else

#define RED ""

#define WHITE ""

#define RESET ""

#endif

char prompt[255] = {'\0'};

snprintf(prompt, 255, "%sexample%s@%sexample%s$ ", WHITE, RED, WHITE, RESET);

If you add that code to a program and call linenoise(prompt) the cursor moves over 20pts to the right but displays text correctly.

If you compile the same program with the -DNO_COLOR flag then the issue does not happen

I traced the cursor move to this line:

if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */

The only work-around I found is to place two prompts (one above the real one) so at least part of it is in color.

Here is a picture comparing the two, note the white cursor on the left

2018-08-06-042855_1366x768_scrot

@mckenney5 mckenney5 changed the title Cursor moves far to the right if prompt has colors Bug: Cursor moves far to the right if prompt has colors Aug 7, 2018
mckenney5 added a commit to mckenney5/qsh that referenced this issue Aug 7, 2018
Replaced the UI library with a more maintained version.
The new library fixed this issue: antirez/linenoise#158
@jean-claude-borg
Copy link

yep i am having the exact same problem

@4zv4l
Copy link

4zv4l commented Oct 21, 2024

Having the same problem, any workaround for now (except not using colors xD) ?

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