Permalink
Browse files

[issue #59] Clear a possibly interrupted ANSI color code on signal te…

…rmination.
  • Loading branch information...
trentm committed Nov 15, 2012
1 parent af002db commit 70f8d4d4daade280e19533f9c3d4ad67b8dc2809
Showing with 10 additions and 1 deletion.
  1. +2 −1 CHANGES.md
  2. +8 −0 bin/bunyan
View
@@ -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
View
@@ -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
@@ -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);
}
@@ -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;

0 comments on commit 70f8d4d

Please sign in to comment.