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

Fix Issue #25: Inappropriate Redrawn Multi-Line Asks #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

axelKingsley
Copy link

Commit Message

#25

Prompts were causing bad user experience in situations where
the prompt contains multiple lines. This is because prompt-sync
will redraw the prompt as you type, and assumes it only takes
up one line.

The fix provided prints the whole ask string, before reassigning
ask to be only the final line of the prompt. This way, redraws
don't affect above lines.

Testing

Wrote and executed a simple script that captures multi-line and single-line prompts.

const prompt = require('./prompt-sync')({sigint: true});        
                                                                
let response = prompt(`Multi-Line                               
Prompts                                                         
Are                                                             
Cool: `);                                                       
                                                                
console.log(`You Said: ${response}`);                           
                                                                
response = prompt(`Single-Line Prompts are Fine Too I Guess: `);
                                                                
console.log(`You Said: ${response}`);                           

And Executed:

[axel@arch prompt-sync]$ node test.js 
Multi-Line
Prompts
Are
Cool: yes they are
You Said: yes they are
Single-Line Prompts are Fine Too I Guess: yep
You Said: yep

Potential Side-Effects

I looked over the index.js and didn't see anything concerning, but if there's an expectation that the ask variable is the full string provided by the user, that expectation would be broken beyond line 79.

heapwolf#25

Prompts were causing bad user experience in situations where
the prompt contains multiple lines. This is because prompt-sync
will redraw the prompt as you type, and assumes it only takes
up one line.

The fix provided prints the whole ask string, before reassigning
ask to be only the final line of the prompt. This way, redraws
don't affect above lines.
@axelKingsley
Copy link
Author

One deficiency I noticed after using this for a while: If the users input should cause a line-wrap in their terminal, the original problem (reprint on every keystroke) starts back up. I would suspect this means that the printing itself should be reconsidered, but this commit at least improves the situation, if there are no side-effects.

@mitchell-merry
Copy link

would very much appreciate a merge here!

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

Successfully merging this pull request may close these issues.

2 participants