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

Wrong cursor position with history and colored label #41

Open
marmotz opened this issue Apr 28, 2020 · 0 comments
Open

Wrong cursor position with history and colored label #41

marmotz opened this issue Apr 28, 2020 · 0 comments

Comments

@marmotz
Copy link

marmotz commented Apr 28, 2020

Hi,

I have a problem when I use a colored label (with \u001b[* characters) and I navigate throw history.
On UP there is no problem, but on DOWN, cursor is at a wrong place.

I see that UP and DOWN have different code to display label and history and I don't know why.

So, I don't know if you should modify line 114 to be identical to line 99:

@@ -111,7 +111,7 @@ function create(config) {
               str = history.next();
               insert = str.length;
             }
-            process.stdout.write('\u001b[2K\u001b[0G'+ ask + str + '\u001b['+(insert+ask.length+1)+'G');
+            process.stdout.write('\u001b[2K\u001b[0G'+ ask + str);
             break;
           case '\u001b[D': //left arrow
             if (masked) break;

or if you should clean ask variable:

@@ -58,6 +58,7 @@ function create(config) {
       value = opts.value;
     }
     ask = ask || '';
+    var rawAsk = ask.replace(/\u001b\[(?:\d+;)\d+[a-zA-Z]/g, '');
     var echo = opts.echo;
     var masked = 'echo' in opts;
     autocomplete = opts.autocomplete || autocomplete;
@@ -111,7 +112,7 @@ function create(config) {
               str = history.next();
               insert = str.length;
             }
-            process.stdout.write('\u001b[2K\u001b[0G'+ ask + str + '\u001b['+(insert+ask.length+1)+'G');
+            process.stdout.write('\u001b[2K\u001b[0G'+ ask + str + '\u001b['+(insert+rawAsk.length+1)+'G');
             break;
           case '\u001b[D': //left arrow
             if (masked) break;

or another solution I didn't see.

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

1 participant