Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93d27ea

Browse files
authored
feat: add a copy button to serial monitor (#2718)
* Add a copy output button to serial monitorIf the arduino collects some data that you want to store on yourcomputer, a rather simple way is to write it to the serial monitor andcopy it to the clipboard. This commit introduces a button that copiesthe whole content of the serial monitor to the clipboard to make thisrather simple. It is a new component added to the menu, and does notchange the behaviour of other compontents.* Test merging lines to str in serial monitor utilsAdds a test for merging one or more lines to a single string. It issupposed to just concatenate the content of the lines, without doinganything else. This method is used when copying the serial monitor content tothe clipboard.* Add copy output translation keyThis serves as an addition to the previous commits. It is the result ofrunning `yarn i18n:generate` on the state after adding the copy outputbutton to the serial monitor (see2df3f46). I hope that this willresolve the current Github action failure.* Improve readability for serial monitor utilsReplace return statement in inline method by direct statement, someminor formatting changes. Does not affect the functionality.* Rename linesToMergedStr in monitor-utilsRenames the method linesToMergedStr to joinLines in the serial monitorutils. This brings the name more in line with truncateLines. Nofunctionality changes.* Move label and icon registration for copy serialMoves the registration of the label and icon for the copy outputbutton of the serial monitor to the toolbar item registration. Before,it happened at the command registration, but is not necessary at thislevel, as the icon and label are meant for the toolbar button only.* Do not update widget when copying outputNo longer updates the serial monitor output after its content is copied.Copying the content does not change anything for the view, so there isno need to update.
1 parent155f0ae commit93d27ea

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

‎arduino-ide-extension/src/browser/serial/monitor/monitor-utils.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ export function truncateLines(
6767
}
6868
return[lines,charCount];
6969
}
70+
71+
exportfunctionjoinLines(lines:Line[]):string{
72+
returnlines.map((line:Line)=>line.message).join('');
73+
}

‎arduino-ide-extension/src/browser/serial/monitor/monitor-view-contribution.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export namespace SerialMonitor {
5252
},
5353
'vscode/output.contribution/clearOutput.label'
5454
);
55+
exportconstCOPY_OUTPUT={
56+
id:'serial-monitor-copy-output',
57+
};
5558
}
5659
}
5760

@@ -149,6 +152,12 @@ export class MonitorViewContribution
149152
'Clear Output'
150153
),
151154
});
155+
registry.registerItem({
156+
id:SerialMonitor.Commands.COPY_OUTPUT.id,
157+
command:SerialMonitor.Commands.COPY_OUTPUT.id,
158+
icon:codicon('copy'),
159+
tooltip:nls.localize('arduino/serial/copyOutput','Copy Output'),
160+
});
152161
}
153162

154163
overrideregisterCommands(commands:CommandRegistry):void{
@@ -161,6 +170,15 @@ export class MonitorViewContribution
161170
}
162171
},
163172
});
173+
commands.registerCommand(SerialMonitor.Commands.COPY_OUTPUT,{
174+
isEnabled:(widget)=>widgetinstanceofMonitorWidget,
175+
isVisible:(widget)=>widgetinstanceofMonitorWidget,
176+
execute:(widget)=>{
177+
if(widgetinstanceofMonitorWidget){
178+
widget.copyOutput();
179+
}
180+
},
181+
});
164182
if(this.toggleCommand){
165183
commands.registerCommand(this.toggleCommand,{
166184
execute:()=>this.toggle(),

‎arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import{MonitorModel}from'../../monitor-model';
2929
import{FrontendApplicationStateService}from'@theia/core/lib/browser/frontend-application-state';
3030
import{serialMonitorWidgetLabel}from'../../../common/nls';
31+
import{ClipboardService}from'@theia/core/lib/browser/clipboard-service';
3132

3233
@injectable()
3334
exportclassMonitorWidgetextendsReactWidget{
@@ -47,6 +48,7 @@ export class MonitorWidget extends ReactWidget {
4748
*/
4849
protectedclosing=false;
4950
protectedreadonlyclearOutputEmitter=newEmitter<void>();
51+
protectedreadonlycopyOutputEmitter=newEmitter<void>();
5052

5153
@inject(MonitorModel)
5254
privatereadonlymonitorModel:MonitorModel;
@@ -56,6 +58,8 @@ export class MonitorWidget extends ReactWidget {
5658
privatereadonlyboardsServiceProvider:BoardsServiceProvider;
5759
@inject(FrontendApplicationStateService)
5860
privatereadonlyappStateService:FrontendApplicationStateService;
61+
@inject(ClipboardService)
62+
privatereadonlyclipboardService:ClipboardService;
5963

6064
privatereadonlytoDisposeOnReset:DisposableCollection;
6165

@@ -102,6 +106,10 @@ export class MonitorWidget extends ReactWidget {
102106
this.clearOutputEmitter.fire(undefined);
103107
this.update();
104108
}
109+
110+
copyOutput():void{
111+
this.copyOutputEmitter.fire();
112+
}
105113

106114
overridedispose():void{
107115
this.toDisposeOnReset.dispose();
@@ -247,6 +255,8 @@ export class MonitorWidget extends ReactWidget {
247255
monitorModel={this.monitorModel}
248256
monitorManagerProxy={this.monitorManagerProxy}
249257
clearConsoleEvent={this.clearOutputEmitter.event}
258+
copyOutputEvent={this.copyOutputEmitter.event}
259+
clipboardService={this.clipboardService}
250260
height={Math.floor(this.widgetHeight-50)}
251261
/>
252262
</div>

‎arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-output.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { Event } from '@theia/core/lib/common/event';
33
import{DisposableCollection}from'@theia/core/lib/common/disposable';
44
import{areEqual,FixedSizeListasList}from'react-window';
55
importdateFormatfrom'dateformat';
6-
import{messagesToLines,truncateLines}from'./monitor-utils';
6+
import{messagesToLines,truncateLines,joinLines}from'./monitor-utils';
77
import{MonitorManagerProxyClient}from'../../../common/protocol';
88
import{MonitorModel}from'../../monitor-model';
9+
import{ClipboardService}from'@theia/core/lib/browser/clipboard-service';
910

1011
exporttypeLine={message:string;timestamp?:Date;lineLen:number};
1112

@@ -74,6 +75,9 @@ export class SerialMonitorOutput extends React.Component<
7475
this.props.clearConsoleEvent(()=>
7576
this.setState({lines:[],charCount:0})
7677
),
78+
this.props.copyOutputEvent(()=>
79+
this.props.clipboardService.writeText(joinLines(this.state.lines))
80+
),
7781
this.props.monitorModel.onChange(({ property})=>{
7882
if(property==='timestamp'){
7983
const{ timestamp}=this.props.monitorModel;
@@ -130,6 +134,8 @@ export namespace SerialMonitorOutput {
130134
readonlymonitorModel:MonitorModel;
131135
readonlymonitorManagerProxy:MonitorManagerProxyClient;
132136
readonlyclearConsoleEvent:Event<void>;
137+
readonlycopyOutputEvent:Event<void>;
138+
readonlyclipboardService:ClipboardService;
133139
readonlyheight:number;
134140
}
135141

‎arduino-ide-extension/src/test/browser/monitor-utils.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai';
22
import{
33
messagesToLines,
44
truncateLines,
5+
joinLines,
56
}from'../../browser/serial/monitor/monitor-utils';
67
import{Line}from'../../browser/serial/monitor/serial-monitor-send-output';
78
import{set,reset}from'mockdate';
@@ -15,13 +16,15 @@ type TestLine = {
1516
charCount:number;
1617
maxCharacters?:number;
1718
};
19+
expectedJoined?:string;
1820
};
1921

2022
constdate=newDate();
2123
consttestLines:TestLine[]=[
2224
{
2325
messages:['Hello'],
2426
expected:{lines:[{message:'Hello',lineLen:5}],charCount:5},
27+
expectedJoined:'Hello',
2528
},
2629
{
2730
messages:['Hello','Dog!'],
@@ -36,6 +39,7 @@ const testLines: TestLine[] = [
3639
],
3740
charCount:10,
3841
},
42+
expectedJoined:'Hello\nDog!'
3943
},
4044
{
4145
messages:['Dog!'],
@@ -67,6 +71,7 @@ const testLines: TestLine[] = [
6771
{message:"You're a good boy!",lineLen:8},
6872
],
6973
},
74+
expectedJoined:"Hello Dog!\n Who's a good boy?\nYou're a good boy!",
7075
},
7176
{
7277
messages:['boy?\n',"You're a good boy!"],
@@ -116,6 +121,7 @@ const testLines: TestLine[] = [
116121
{message:'Yo',lineLen:2},
117122
],
118123
},
124+
expectedJoined:"Hello Dog!\nWho's a good boy?\nYo",
119125
},
120126
];
121127

@@ -165,6 +171,10 @@ describe('Monitor Utils', () => {
165171
});
166172
expect(totalCharCount).to.equal(charCount);
167173
}
174+
if(testLine.expectedJoined){
175+
constjoined_str=joinLines(testLine.expected.lines);
176+
expect(joined_str).to.equal(testLine.expectedJoined);
177+
}
168178
});
169179
});
170180
});

‎i18n/en.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
"autoscroll":"Autoscroll",
436436
"carriageReturn":"Carriage Return",
437437
"connecting":"Connecting to '{0}' on '{1}'...",
438+
"copyOutput":"Copy Output",
438439
"message":"Message (Enter to send message to '{0}' on '{1}')",
439440
"newLine":"New Line",
440441
"newLineCarriageReturn":"Both NL & CR",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp