-
Notifications
You must be signed in to change notification settings - Fork 64
ANSI escape codes show up in output when pressing arrow keys, e.g., ^[[A^[[B^[[C^[[D #22
Comments
Hi specious, thanks for your post. readlineSync deliberately ignore the keys that control something. (e.g. arrow, backspace, home, etc.) And current Node doesn't support controlling the readline system library (e.g. like the bash). I think that, if you want to let your program run in many environments, you should not use the ANSI escape sequence, or you should consider some measures such as chalk |
There is no reply, and I close this issue. |
As I said, that behavior differs depending on the environment. That is, it calls the readline system library such as GNU readline. For example, your sample code in Win 8.1 + Node v4.2.1 or Node v0.12.6: console.log('You typed: ' + require('readline-sync').question('Type here: ')); First, I typed the text only, 2 times. And then, I pushed the
And then, I pushed the If you want to let the user use arrow keys in many environments, you should test it in each environments. The "read" module is wrapper of Readline that is core module. For example: var readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('Type here: ', function(answer) {
console.log('You typed: ', answer);
readline.close();
}); |
Of course, I will update readlineSync when those keys be controllable. |
@anseki, thank you for your reply, and I appreciate the suggestion to just use readline if that's all I need. I just switched to using native readline with I originally thought that readline-sync was just an easy way to use readline without needing a callback. Now I took a closer look and realised it doesn't use readline at all and reads stdin directly. So, I take it the point of using readline-sync is to be able to read keyboard input without the calling function having to become asynchronous. For what it's worth, I just tested the latest readline-sync 1.4.10 in my terminal on a linux system, and it still doesn't let me edit the line and instead prints these same control characters. In other words, it prints control characters instead of moving the cursor on my system. However, if I run the application with rlwrap, then the line becomes editable. |
Hi @specious, thank you for the comment. |
One would think, but what if you've got a synchronous function that other modules depend on (for example As I understand, in some cases an API update may seem too bothersome. |
Yes I know that the module is rather used for Utility Methods. |
ANSI escape codes (e.g.,
^[[A^[[B^[[C^[[D
) show up in the output when user input is being acquired usingreadline-sync@1.2.21
Here's a screenshot of the behavior when using
bitly-client@1.0.1
, where the sequence "up, down, right, left" was recorded as an input of"[A[B[C[D"
:Here's a test script that exhibits the behavior:
Expected behavior I think is for left and right keys to move the caret and up/down arrows to flip through the input history (if enabled). I tested in several terminal emulators on OS X 10.9 with the same results.
The text was updated successfully, but these errors were encountered: