From 70f8d4d4daade280e19533f9c3d4ad67b8dc2809 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 14 Nov 2012 19:27:53 -0800 Subject: [PATCH] [issue #59] Clear a possibly interrupted ANSI color code on signal termination. --- CHANGES.md | 3 ++- bin/bunyan | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 99e10e6..6cf00e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/bin/bunyan b/bin/bunyan index 9d17e78..4a21c2a 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -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;