diff --git a/lib/build.js b/lib/build.js index 5102a3aa..741e92ab 100644 --- a/lib/build.js +++ b/lib/build.js @@ -18,6 +18,7 @@ export default { this.tools = [ require('./atom-build') ]; this.linter = null; + this.detectConsoleEncoding(); this.setupTargetManager(); this.setupBuildView(); this.setupErrorMatcher(); @@ -47,6 +48,21 @@ export default { atom.packages.onDidActivateInitialPackages(() => this.targetManager.refreshTargets()); }, + detectConsoleEncoding() { + this.encoding = 'utf8'; + + if (process.platform === 'win32') { + // On windows, `chcp` commnad prints current console codepage. + // see: https://ss64.com/nt/chcp.html + require('child_process').exec('chcp', (err, stdout, stderr) => { + if (stdout) { + const i = stdout.lastIndexOf(':'); + this.encoding = 'cp' + stdout.slice(i + 1).trim(); + } + }); + } + }, + setupTargetManager() { const TargetManager = require('./target-manager'); this.targetManager = new TargetManager(); @@ -161,14 +177,15 @@ export default { ); } + const iconv = require('iconv-lite'); let stdout = ''; let stderr = ''; - this.child.stdout.setEncoding('utf8'); - this.child.stderr.setEncoding('utf8'); - this.child.stdout.on('data', d => (stdout += d)); - this.child.stderr.on('data', d => (stderr += d)); - this.child.stdout.pipe(this.buildView.terminal); - this.child.stderr.pipe(this.buildView.terminal); + const decodeStdout = this.child.stdout.pipe(iconv.decodeStream(this.encoding)); + const decodeStderr = this.child.stderr.pipe(iconv.decodeStream(this.encoding)); + decodeStdout.on('data', d => (stdout += d)); + decodeStderr.on('data', d => (stderr += d)); + decodeStdout.pipe(this.buildView.terminal); + decodeStderr.pipe(this.buildView.terminal); this.child.killSignals = (target.killSignals || [ 'SIGINT', 'SIGTERM', 'SIGKILL' ]).slice(); this.child.on('error', (err) => { diff --git a/package.json b/package.json index 8a6b52be..fbed7feb 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "cross-spawn": "^4.0.2", "cson-parser": "^1.3.0", "getmac": "^1.0.7", + "iconv-lite": "^0.4.23", "js-yaml": "^3.4.6", "term.js": "https://github.com/jeremyramin/term.js/tarball/de1635fc2695e7d8165012d3b1d007d7ce60eea2", "tree-kill": "^1.0.0",