-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
fix: possible fix for isTTY and GitBash #36
Conversation
fixes terkelg#35, closes terkelg#19 Signed-off-by: Charlike Mike Reagent <[email protected]>
Signed-off-by: Charlike Mike Reagent <[email protected]>
Signed-off-by: Charlike Mike Reagent <[email protected]>
7c042e3: this.clear() doesn't exist
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, but almost~!
Let's clean up that .gitignore
... nothing there is needed.
And as mentioned, clear()
doesn't exist. Looks like you forgot to import from util
file.
Cause of BugIn a TTY environment, such as VS Code's integrated terminal, Prompts works as intended. In non-TTY environments like Git Bash: The cause of the bug comes from running a file with a Node shebang in a non-TTY environment. "bin": {
"prompts-test": "promptsTest.js"
} then running the command prompts-test will both result in a broken Prompts application. WorkaroundExplicitly run a file with Node: |
@lukeed what's not needed? 😆
It was meant to be
@FoRVaiS, what about that? "bin": {
"prompts-test": "node promptsTest.js"
} I have never tried it. |
"bin": {
"prompts-test": "node promptsTest.js"
} left me an error saying that it couldn't find promptsTest.js. I fail to understand why that happens, since calling the file directly |
Try with absolute path or I had problems few times when just defining
So since then i always prepend |
"bin": {
"prompts-test": "node ./promptsTest.js"
} outputs this npm err. I don't get the chance to even run the test $ npm publish; npm install -g local-promptstest
+ [email protected]
npm ERR! path C:\Program Files\nodejs\node_modules\local-promptstest\node .\index.js
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod 'C:\Program Files\nodejs\node_modules\local-promptstest\node .\index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\${user}\AppData\Roaming\npm-cache\_logs\2018-03-03T02_22_02_884Z-debug.log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is pretty critical so I want to make sure that we get everything right and understand why/how everything works. No guessing at this level 👍
.gitignore
Outdated
@@ -1,3 +1,10 @@ | |||
node_modules | |||
.DS_Store | |||
*.lock | |||
*.log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove .gitignore from this commit. The ignored files are not related to this project. Include them in your own global gitignore if needed.
@@ -16,7 +16,7 @@ class Prompt extends EventEmitter { | |||
this.out = process.stdout; | |||
|
|||
const rl = readline.createInterface(this.in); | |||
readline.emitKeypressEvents(this.in, this.rl); | |||
readline.emitKeypressEvents(this.in, rl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have to look into this. The second param to emitKeypressEvents
is optional - do we even need it?
Also have to dig deeper into createInterface
options like crlfDelay
and terminal
https://nodejs.org/api/readline.html#readline_readline_createinterface_options
How can I test/emulate a non-TTY environment on mac? |
This looks like a rendering issue. In this demo, pressing the down arrow twice lands me at the correct option but since it never rerenders, we see it stuck in the initial position. I added an output to report on the cursor's location but it never renders when Ignore the |
Based on my 'bad rendering' theory, I've traced a potential problem to Does anyone happen to know if using If there is, maybe these codes don't work when using a shebang? const erase = {
screen: `${ESC}2J`,
up: `${ESC}1J`,
down: `${ESC}J`,
line: `${ESC}2K`,
lineEnd: `${ESC}K`,
lineStart: `${ESC}1K`,
lines(count) {
let clear = '';
for (let i = 0; i < count; i++)
clear += this.line + (i < count - 1 ? cursor.up() : '');
if (count)
clear += cursor.left;
return clear;
}
} |
@FoRVaiS i think that's the diff, yea. And colors. |
Signed-off-by: Charlike Mike Reagent <[email protected]>
It's really frustrating to play on guesses... @FoRVaiS can you please try now ;d |
Signed-off-by: Charlike Mike Reagent <[email protected]>
Thanks! Cool, starting to see fix :D |
Nope, text and select are not okay yet.
I still haven't found solid evidence that the problems come from |
lib/elements/prompt.js
Outdated
@@ -39,8 +39,8 @@ class Prompt extends EventEmitter { | |||
if (this.in.isTTY) { | |||
this.in.setRawMode(false); | |||
} else { | |||
// we can't use `utils.clear()`, because it expect `prompt` string | |||
this.out.write(erase.line + cursor.prevLine()); | |||
this.clear = clear(this.prompt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.prompt
should be available, because this.close
is called after the this.render
inside the submit()
...
Also writing the result of clear
to this.clear
so it can be available in the next call of this.render
Signed-off-by: Charlike Mike Reagent <[email protected]>
All this should fix the |
4fdaf6e No change in output. |
Arrrghh. Does anyone know is AppVeyor using GitBash or such? Maybe adding AppVeyor would help the things a bit. But in any way, such problems are hard cuz is user interaction.. |
So using both #!/usr/bin/env node
const { erase } = require('sisteransi');
const out = process.stdout;
console.log('Test 1');
console.log('Test 2');
console.log('Test 3');
console.log('Test 4');
console.log('Test 5');
console.log('Test 6');
out.write(erase.lines(3 + 1)); Expected Output:Test 1 Output:Test 1 |
@terkelg @olstenlarck So I'm 110% sure I've found the source of the problem. The problem is caused by stdin not reading keypress events in non-TTY instances until a user hits the enter key. Using setRawMode skips the requirement of having to hit the enter key. To be perfectly honest, this looks exponentially more like a Git Bash issue... Other popular prompt-type packages don't work as intended in Git Bash either. I have a feeling they might have abandoned a fix for Git Bash users :x. Main thread to read: This person gets the same queuing problem: |
@FoRVaiS thank you for doing so much research on this one. Appreciate it! It's really hard for me to come up with a work-around for this when I can't reproduce the issue |
@terkelg No worries, if a workaround/fix can be found, then it benefits us both. Otherwise, at least you would know what the exact problem is, when someone else has the same problem. :P I'm unable to think of a workaround. The only solution that I can come up with, that doesn't require a redesign of the input system, would be to simulate an 'enter' keypress but all the packages that do keyboard simulation require Java's Robot package. If a workaround is proposed, I'd be glad to try it out. |
Great! 🎉 So much thank you for that! In that case, I think we definitely should close the PR. It's not specific to this prompt module, but to Git Bash, so not make sense to touch on our side. Adding notice on the README and pointing to this PR or to #35 issue. |
fixes #35, closes #19