Skip to content

Commit

Permalink
added gracefulExit option
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Apr 30, 2022
1 parent 1f0c40e commit 17b9c64
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 977 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Branch 3.x ##

### 3.11.0 ###

* Added: `gracefulExit` option (enabled by default) to stop the bars in case of `SIGINT` or `SIGTERM` - this restores most cursor settings before exiting

### 3.10.0 ###

* Changed: foreground color of `preset.shades-grey` is set directly by ANSI codes
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (X11 License)

Copyright (c) 2015-2021 Andi Dittrich
Copyright (c) 2015-2022 Andi Dittrich

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ The following options can be changed
- `barIncompleteChar` (type:char) - character to use as "incomplete" indicator in the bar (default: "-")
- `hideCursor` (type:boolean) - hide the cursor during progress operation; restored on complete (default: false) - pass `null` to keep terminal settings
- `linewrap` (type:boolean) - disable line wrapping (default: false) - pass `null` to keep terminal settings; pass `true` to add linebreaks automatically (not recommended)
- `gracefulExit` (type:boolean) - stop the bars in case of `SIGINT` or `SIGTERM` - this restores most cursor settings before exiting (default: `true`)
- `etaBuffer` (type:int) - number of updates with which to calculate the eta; higher numbers give a more stable eta (default: 10)
- `etaAsynchronousUpdate` (type:boolean) - trigger an eta calculation update during asynchronous rendering trigger using the current value - should only be used for long running processes in conjunction with lof `fps` values and large `etaBuffer` (default: false)
- `synchronousUpdate` (type:boolean) - trigger redraw during `update()` in case threshold time x2 is exceeded (default: true) - limited to single bar usage
Expand Down
6 changes: 6 additions & 0 deletions lib/multi-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ module.exports = class MultiBar extends _EventEmitter{

// update interval
this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);

// add handler to restore cursor settings (stop the bar) on SIGINT/SIGTERM ?
if (this.options.gracefulExit){
process.once('SIGINT', this.stop.bind(this));
process.once('SIGTERM', this.stop.bind(this));
}
}

// add a new bar to the stack
Expand Down
3 changes: 3 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ module.exports = {
// autopadding character - empty in case autopadding is disabled
options.autopaddingChar = options.autopadding ? mergeOption(opt.autopaddingChar, ' ') : '';

// stop bar on SIGINT/SIGTERM to restore cursor settings ?
options.gracefulExit = mergeOption(opt.gracefulExit, true);

return options;
}
};
6 changes: 6 additions & 0 deletions lib/single-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ module.exports = class SingleBar extends _GenericBar{

// update interval
this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);

// add handler to restore cursor settings (stop the bar) on SIGINT/SIGTERM ?
if (this.options.gracefulExit){
process.once('SIGINT', this.stop.bind(this));
process.once('SIGTERM', this.stop.bind(this));
}
}

// internal render function
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli-progress",
"version": "3.10.0",
"version": "3.11.0",
"description": "easy to use progress-bar for command-line/terminal applications",
"keywords": [
"cli",
Expand Down Expand Up @@ -35,11 +35,11 @@
"author": "Andi Dittrich (https://andidittrich.com)",
"license": "MIT",
"dependencies": {
"string-width": "^4.2.0"
"string-width": "^4.2.3"
},
"devDependencies": {
"eslint": "^6.4.0",
"eslint": "^8.14.0",
"eslint-config-aenondynamics": "^0.2.0",
"mocha": "^7.1.1"
"mocha": "^9.2.2"
}
}
Loading

0 comments on commit 17b9c64

Please sign in to comment.