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

Process interrupt ignored when using cli-progress v3.11 #126

Open wmelton opened 2 years ago

wmelton commented 2 years ago

When using cli-progress, if you attempt to interrupt the process using ctrl+c the command is ignored until the process fully completes.

Reading through the readme I may have missed how this is supposed to be handled, but I do not see any config options to specify how to handle a kill request from a user.

AndiDittrich commented 2 years ago

an option called gracefulExit has been added to v3.11 (see https://github.com/npkgz/cli-progress/blob/master/CHANGES.md) which restores the terminal state on SIGINT/SIGTERM

hfabio commented 2 years ago

an option called gracefulExit has been added to v3.11 (see https://github.com/npkgz/cli-progress/blob/master/CHANGES.md) which restores the terminal state on SIGINT/SIGTERM

even using this option I still face the same behaviour

AndiDittrich commented 2 years ago

set gracefulExit: false to restore the "old" behaviour. i've to check the node.js docs regarding the SIGINT listener

AndiDittrich commented 2 years ago

from the docs

'SIGTERM' and 'SIGINT' have default handlers on non-Windows platforms that reset the terminal mode before exiting with code 128 + signal number. If one of these signals has a listener installed, its default behavior will be removed (Node.js will no longer exit).

i wasn't aware of this side effect. sry!

the question is how to solve this (putting and process.exit on the end of the listener may avoids users to add their own actions..)

wmelton commented 2 years ago

This is a great library! The ability to hard stop a script from cli is essential though.

AndiDittrich commented 2 years ago

set gracefulExit: false - this will be the default value in the upcoming hotfix

ivanakcheurov commented 1 year ago

I use cli-progress 3.12.0 I tried:

const bar1 = new cliProgress.SingleBar({gracefulExit: true}, cliProgress.Presets.shades_classic);

and

const bar1 = new cliProgress.SingleBar({gracefulExit: false}, cliProgress.Presets.shades_classic);

both don't kill the node process after hitting ctrl+c in bash (the progress continues to run and the node process continues to work).