Added support for output with no new line (fix #51)

This commit is contained in:
WebFreak001 2016-03-23 23:07:07 +01:00
commit 786ed5b3bd

View file

@ -227,6 +227,12 @@ export class MI2 extends EventEmitter implements IBackend {
this.onOutput(this.buffer.substr(0, end)); this.onOutput(this.buffer.substr(0, end));
this.buffer = this.buffer.substr(end + 1); this.buffer = this.buffer.substr(end + 1);
} }
if (this.buffer.length) {
if (this.onOutputPartial(this.buffer))
{
this.buffer = "";
}
}
} }
stderr(data) { stderr(data) {
@ -239,6 +245,10 @@ export class MI2 extends EventEmitter implements IBackend {
this.onOutputStderr(this.errbuf.substr(0, end)); this.onOutputStderr(this.errbuf.substr(0, end));
this.errbuf = this.errbuf.substr(end + 1); this.errbuf = this.errbuf.substr(end + 1);
} }
if (this.errbuf.length) {
this.logNoNewLine("stderr", this.errbuf);
this.errbuf = "";
}
} }
onOutputStderr(lines) { onOutputStderr(lines) {
@ -248,6 +258,14 @@ export class MI2 extends EventEmitter implements IBackend {
}); });
} }
onOutputPartial(line) {
if (couldBeOutput(line)) {
this.logNoNewLine("stdout", line);
return true;
}
return false;
}
onOutput(lines) { onOutput(lines) {
lines = <string[]>lines.split('\n'); lines = <string[]>lines.split('\n');
lines.forEach(line => { lines.forEach(line => {
@ -537,6 +555,10 @@ export class MI2 extends EventEmitter implements IBackend {
}); });
} }
logNoNewLine(type: string, msg: string) {
this.emit("msg", type, msg);
}
log(type: string, msg: string) { log(type: string, msg: string) {
this.emit("msg", type, msg[msg.length - 1] == '\n' ? msg : (msg + "\n")); this.emit("msg", type, msg[msg.length - 1] == '\n' ? msg : (msg + "\n"));
} }