From ec1a7c5f99e68030984c4da7e46a025d18c7a8da Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 3 Jul 2014 09:24:28 -0400 Subject: [PATCH] feature(win) restore codepage before quit --- lib/server/win.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/server/win.js b/lib/server/win.js index 8018fb24..ca503882 100644 --- a/lib/server/win.js +++ b/lib/server/win.js @@ -65,13 +65,37 @@ * windows use unicode on non English versions */ - if (process.platform === 'win32') - exec('chcp 65001', function(error, stdout, stderror) { - if (error) - console.log(error); - - if (stderror) - console.log(stderror); - }); + if (process.platform === 'win32') + getCodePage(function(codepage) { + if (codepage) { + process.on('SIGINT', function() { + exec('chcp ' + codepage, function() { + process.exit(); + }); + }); + + exec('chcp 65001', function(error, stdout, stderror) { + if (error) + console.log(error); + + if (stderror) + console.log(stderror); + }); + } + }); } + + function getCodePage(callback) { + exec('chcp', function(error, stdout, stderror) { + var index, codepage; + + if (!error && !stderror && stdout) { + index = stdout.indexOf(':'); + codepage = stdout.slice(index + 2); + } + + callback(codepage); + }); + } + })();