npkgz / cli-progress

:hourglass: easy to use progress-bar for command-line/terminal applications
https://www.npmjs.com/package/cli-progress
MIT License
1.11k stars 84 forks source link

Logs being truncated after exiting process. #138

Closed adamawang closed 1 year ago

adamawang commented 1 year ago

Hi @AndiDittrich, this seems to be happening when you ctrl+c when a multibar is in progress. If you have a log that prints a long string of text that is more than one line, any subsequent line is truncated. Not sure what is happening there, could it be related to linewrap or clearline in the terminal.js file?

Probably the same issue to https://github.com/npkgz/cli-progress/issues/120

To repro:

exports.handler = async options => {
  logger.log(
    'Hi this is very long text. Hi this is very long text. Hi this is very long text. Hi this is very long text. Hi this is very long text. Hi this is very long text. Hi this is very long text. '
  );
  const multibar = new cliProgress.MultiBar(
    {
      hideCursor: true,
      format: '[{bar}] {percentage}% | {taskType}',
    },
    cliProgress.Presets.rect
  );
  const task1 = multibar.create(100, 0, { taskType: 'task 1' });
  const task2 = multibar.create(100, 0, { taskType: 'task 2' });

  for (let i = 0; i < 10; i++) {
    task1.increment(10, { taskType: 'task 1' });
    task2.increment(10, { taskType: 'task 2' });
    await new Promise(res => setTimeout(res, 1000));
  }
  multibar.stop();

  process.exit(EXIT_CODES.SUCCESS);
};

Screenshot of it happening, where between the two runs, I hit ctrl + c to stop the command:

Screenshot 2023-03-09 at 17 33 42

Version numbers:

"cli-progress": "^3.11.2",
"node": "18.7.0"
AndiDittrich commented 1 year ago

use gracefulExit: true - otherwise the terminal settings are not restored by the exit handler. but keep in mind that you've to add a custom exit handler manually which terminates your app

adamawang commented 1 year ago

Awesome, thank you for the suggestion that seems to have worked!