Masked prompt answer contains unicode characters
tobiasmuecksch opened this issue · 3 comments
tobiasmuecksch commented
Introduction
I'm implement a cli tool using oclif.
Versions:
"@oclif/command": "^1.5.18",
"@oclif/config": "^1.13.2",
"@oclif/plugin-help": "^2.2.0",
"chalk": "^2.4.2",
"cli-ux": "^5.3.1",
"tslib": "^1.10.0",
Example:
The following code is inside an oclif command class.
import { cli } from 'cli-ux';
// some command class stuff
async run() {
const result = await cli.prompt('Please enter your name', {type: 'mask'});
// Make unicode characters visible, because the console won't print them. But they are still
// present in the string.
result = JSON.stringify(_string).replace(/((^")|("$))/g, '').trim();
this.log('You picked the name: " ' + result + ' "');
}
Problem:
When I start the command, and enter "John Doe" this output looks like this:
You picked the name: " John Doe\u001b[D\u001b[D\u001b[D\u001b[Ahnung\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[C\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D\u001b[D "
I entered Jogn Doe
and realized that I entered g
instead of h
. I therefore used the arrow keys to go back and deleted the g
and replaced it with h
This happened on a Debian 10
machine on the standard console (bash).
Why does this happen, and how can I fix it?
I also noticed:
- That using the backspace/delete key on the keyboard also allows to remove the prompts message on the left side. This is unintended behavior for sure.
- using the arrow keys causes strange behavior for all prompt types
tobiasmuecksch commented
Since I cannot reproduce this issue anymore at the moment, I'll close this issue for now.
tobiasmuecksch commented
Okay I found out why I couldn't reproduce it. I've changed the issue above accordingly.
RasPhilCo commented
Unfortunately I'm unable to recreate your results. Prompt is working as expected.