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

Progress display messes up on console input #29

Open
erhhung opened this issue Aug 11, 2018 · 1 comment
Open

Progress display messes up on console input #29

erhhung opened this issue Aug 11, 2018 · 1 comment

Comments

@erhhung
Copy link

erhhung commented Aug 11, 2018

I've noticed that with any of the examples, but especially multi-bar ones, that if I start typing while the progress bars are moving, the console just gets filled with uninterpreted ANSI escape sequences on every tick, and the bar rendering completely breaks.

I don't see a need to accept typed input during progress monitoring, except perhaps ESC to cancel, but the console rendering positions should not break down.

I'm running the examples in a Mac Terminal window with Bash if that makes a difference.

@erhhung
Copy link
Author

erhhung commented Aug 15, 2018

Perhaps this can only be handled outside of the core component. I've solved this issue by putting stdin into raw mode and explicitly handling keys like ESC and SIGINT before I begin the concurrent progress bars:

const {stdin} = process;

stdin.setRawMode(true);
stdin.setEncoding('utf8');
stdin.on('data', (key) => {
  if (key === '\u001b' || // ESC
      key === '\u0003') { // Ctrl-C
    process.exit();
  }
});
stdin.resume();

As I'm just writing a CLI app, I just terminate the process, but you could resolve a promise or do some other signaling if you wanted to stop or pause the processing.

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