Skip to content

Commit

Permalink
[issue #59] Clear a possibly interrupted ANSI color code on signal te…
Browse files Browse the repository at this point in the history
…rmination.
  • Loading branch information
trentm committed Nov 15, 2012
1 parent af002db commit 70f8d4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Expand Up @@ -2,7 +2,8 @@

## bunyan 0.16.7 (not yet released)

(nothing yet)
- [issue #59] Clear a possibly interrupted ANSI color code on signal
termination.


## bunyan 0.16.6
Expand Down
8 changes: 8 additions & 0 deletions bin/bunyan
Expand Up @@ -73,6 +73,9 @@ var currLine = null;
// Child dtrace process, if any. Used for signal-handling.
var child = null;

// Whether ANSI codes are being used. Used for signal-handling.
var usingAnsiCodes = false;



//---- support functions
Expand Down Expand Up @@ -1147,6 +1150,10 @@ function asyncForEach(arr, iterator, callback) {

// Try to ensure we close a child 'dtrace' process on signalled exit.
function signalCleanupAndExit(signal) {
if (usingAnsiCodes) {
// Clear possibly interrupted ANSI code (issue #59).
process.stdout.write('\033[0m');
}
if (child) {
child.kill(signal);
}
Expand Down Expand Up @@ -1215,6 +1222,7 @@ function main(argv) {
opts.color = process.stdout.isTTY;
}
}
usingAnsiCodes = opts.color; // intentionally global
var stylize = (opts.color ? stylizeWithColor : stylizeWithoutColor);

var retval = 0;
Expand Down

0 comments on commit 70f8d4d

Please sign in to comment.