buffer last line without new line end

This commit is contained in:
Christopher Homberger
2024-12-01 11:41:36 +01:00
parent 303ba421b8
commit d78e1c19fe

View File

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