ascii-progress icon indicating copy to clipboard operation
ascii-progress copied to clipboard

Progress display messes up on console input

Open erhhung opened this issue 7 years ago • 1 comments

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 avatar Aug 11 '18 01:08 erhhung

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.

erhhung avatar Aug 15 '18 22:08 erhhung