Merge pull request #99 from ChristopherHX/buffer-unfinished-lines-accept-empty-msg

buffer last line without new line end
This commit is contained in:
Sanjula Ganepola
2024-12-01 20:14:10 -05:00
committed by GitHub

View File

@@ -423,15 +423,25 @@ export class Act {
} catch (error: any) { } } catch (error: any) { }
}); });
const handleIO = async (data: any) => { const handleIO = () => {
const lines: string[] = data.toString().split('\n').filter((line: string) => line !== ''); let lastline: string = "";
return async (data: any) => {
let xdata: string = data.toString();
let lines: string[] = xdata.split('\n').filter((line: string) => line !== '');
if (lastline?.length > 0) {
lines[0] = lastline + lines[0];
lastline = "";
}
if (!xdata.endsWith("\n")) {
lastline = lines.pop() || "";
}
for await (const line of lines) { for await (const line of lines) {
const dateString = new Date().toString(); const dateString = new Date().toString();
let message: string; let message: string;
try { try {
const parsedMessage = JSON.parse(line); const parsedMessage = JSON.parse(line);
if (parsedMessage.msg) { if (typeof parsedMessage.msg === 'string') {
message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`;
} else { } else {
message = line; message = line;
@@ -530,6 +540,7 @@ export class Act {
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
} }
await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
}
}; };
let shell = env.shell; let shell = env.shell;
@@ -561,8 +572,8 @@ export class Act {
} }
} }
); );
exec.stdout.on('data', handleIO); exec.stdout.on('data', handleIO());
exec.stderr.on('data', handleIO); exec.stderr.on('data', handleIO());
exec.on('exit', async (code, signal) => { exec.on('exit', async (code, signal) => {
const dateString = new Date().toString(); const dateString = new Date().toString();