Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Split by lines when parsing stdout of build #1276

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,13 @@ export class ArduinoApp {
}
return ret;
}
let stdoutbuf = "";
const stdoutcb = (line: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name line is obviously misleading since it really is chunks of stdout text, not specifically split into lines, so this name should be updated as well.

I suggest stdoutText which is descriptive and also matches the documentation to the spawn function in src/common/util.ts (which is missing an update to match its current parameters, great if you could fix that as well).

With a rename of the function argument in stdoutcb (and fix stderrcb as well at the same time), then you could use stdoutText directly without needing to copy to a stdoutbuf variable.

if (cocopa.callback) {
cocopa.callback(line);
stdoutbuf += line;
let lines = stdoutbuf.split('\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const lines = ...

stdoutbuf = lines.pop()!;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement can be removed, there is no point in updating stdoutbuf after its last usage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stdoutbuf is upvalue variable of the closure, the last update is taking the remain characters that in last line.

lines.forEach((line) => cocopa.callback(line));
}
if (verbose) {
arduinoChannel.channel.append(line);
Expand Down