check for unicode on windows using GetConsoleCP. see #130.

This commit is contained in:
Christopher Jeffrey 2015-04-25 12:32:32 -07:00
parent 38cc1a3ea3
commit 5f993a19d9

View File

@ -2020,7 +2020,7 @@ Tput.prototype.detectUnicode = function() {
+ ':' + process.env.LC_ALL
+ ':' + process.env.LC_CTYPE;
return /utf-?8/i.test(LANG);
return /utf-?8/i.test(LANG) || (this.GetConsoleCP() === 65001);
};
// For some reason TERM=linux has smacs/rmacs, but it maps to `^[[11m`
@ -2130,6 +2130,27 @@ Tput.prototype.parseACS = function(info) {
return data;
};
Tput.prototype.GetConsoleCP = function() {
var ccp;
if (process.platform !== 'win32') {
return -1;
}
try {
ccp = cp.execFileSync(process.env.WINDIR + '\\system32\\chcp.exe', [], {
stdio: 'pipe',
encoding: 'ascii'
});
} catch (e) {
;
}
if (!ccp) ccp = '-1';
return +ccp.trim();
};
/**
* Helpers
*/