Skip to content

feat: Add a copy button to serial monitor #2718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Rename linesToMergedStr in monitor-utils
Renames the method linesToMergedStr to joinLines in the serial monitor
utils. This brings the name more in line with truncateLines. No
functionality changes.
  • Loading branch information
502E532E committed May 3, 2025
commit 503376947c3dff3837f25f4d9142fcbc0c1523bc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export function truncateLines(
return [lines, charCount];
}

export function linesToMergedStr(lines: Line[]): string {
export function joinLines(lines: Line[]): string {
return lines.map((line: Line) => line.message).join('');
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Event } from '@theia/core/lib/common/event';
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import { areEqual, FixedSizeList as List } from 'react-window';
import dateFormat from 'dateformat';
import { messagesToLines, truncateLines, linesToMergedStr } from './monitor-utils';
import { messagesToLines, truncateLines, joinLines } from './monitor-utils';
import { MonitorManagerProxyClient } from '../../../common/protocol';
import { MonitorModel } from '../../monitor-model';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
Expand Down Expand Up @@ -76,7 +76,7 @@ export class SerialMonitorOutput extends React.Component<
this.setState({ lines: [], charCount: 0 })
),
this.props.copyOutputEvent(() =>
this.props.clipboardService.writeText(linesToMergedStr(this.state.lines))
this.props.clipboardService.writeText(joinLines(this.state.lines))
),
this.props.monitorModel.onChange(({ property }) => {
if (property === 'timestamp') {
Expand Down
18 changes: 9 additions & 9 deletions arduino-ide-extension/src/test/browser/monitor-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import {
messagesToLines,
truncateLines,
linesToMergedStr,
joinLines,
} from '../../browser/serial/monitor/monitor-utils';
import { Line } from '../../browser/serial/monitor/serial-monitor-send-output';
import { set, reset } from 'mockdate';
Expand All @@ -16,15 +16,15 @@ type TestLine = {
charCount: number;
maxCharacters?: number;
};
expectedMerged?: string;
expectedJoined?: string;
};

const date = new Date();
const testLines: TestLine[] = [
{
messages: ['Hello'],
expected: { lines: [{ message: 'Hello', lineLen: 5 }], charCount: 5 },
expectedMerged: 'Hello',
expectedJoined: 'Hello',
},
{
messages: ['Hello', 'Dog!'],
Expand All @@ -39,7 +39,7 @@ const testLines: TestLine[] = [
],
charCount: 10,
},
expectedMerged: 'Hello\nDog!'
expectedJoined: 'Hello\nDog!'
},
{
messages: ['Dog!'],
Expand Down Expand Up @@ -71,7 +71,7 @@ const testLines: TestLine[] = [
{ message: "You're a good boy!", lineLen: 8 },
],
},
expectedMerged: "Hello Dog!\n Who's a good boy?\nYou're a good boy!",
expectedJoined: "Hello Dog!\n Who's a good boy?\nYou're a good boy!",
},
{
messages: ['boy?\n', "You're a good boy!"],
Expand Down Expand Up @@ -121,7 +121,7 @@ const testLines: TestLine[] = [
{ message: 'Yo', lineLen: 2 },
],
},
expectedMerged: "Hello Dog!\nWho's a good boy?\nYo",
expectedJoined: "Hello Dog!\nWho's a good boy?\nYo",
},
];

Expand Down Expand Up @@ -171,9 +171,9 @@ describe('Monitor Utils', () => {
});
expect(totalCharCount).to.equal(charCount);
}
if (testLine.expectedMerged) {
const merged_str = linesToMergedStr(testLine.expected.lines);
expect(merged_str).to.equal(testLine.expectedMerged);
if (testLine.expectedJoined) {
const joined_str = joinLines(testLine.expected.lines);
expect(joined_str).to.equal(testLine.expectedJoined);
}
});
});
Expand Down