Skip to content

Commit f26db8d

Browse files
committed
running sketches
1 parent 4f7b8b9 commit f26db8d

File tree

3 files changed

+80
-11
lines changed

3 files changed

+80
-11
lines changed

.vscode/launch.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"request": "launch",
88
"name": "Launch Client",
99
"runtimeExecutable": "${execPath}",
10-
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
10+
"args": [
11+
"--extensionDevelopmentPath=${workspaceRoot}",
12+
"--user-data-dir=${workspaceRoot}/.vscode-test"
13+
],
1114
"outFiles": [
1215
"${workspaceRoot}/client/out/**/*.js",
1316
"${workspaceRoot}/server/out/**/*.js"
@@ -28,7 +31,9 @@
2831
"--extensionTestsPath=${workspaceRoot}/client/out/test/index",
2932
"${workspaceRoot}/client/testFixture"
3033
],
31-
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
34+
"outFiles": [
35+
"${workspaceRoot}/client/out/test/**/*.js"
36+
]
3237
}
3338
]
34-
}
39+
}

client/src/extension.ts

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/* --------------------------------------------------------------------------------------------
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
4-
* ------------------------------------------------------------------------------------------ */
5-
61
import { exec, execSync } from 'child_process';
7-
import { join } from 'path';
8-
import { workspace, ExtensionContext, Uri, FileType, window } from 'vscode';
2+
import { dirname, join } from 'path';
3+
import { workspace, ExtensionContext, Uri, FileType, window, commands, Terminal } from 'vscode';
94

105
import {
116
Executable,
@@ -20,8 +15,9 @@ interface ProcessingVersion {
2015
path: string;
2116
}
2217

18+
let terminal: Terminal | undefined;
19+
2320
export async function activate(context: ExtensionContext) {
24-
// TODO: Find where the Processing app is installed
2521
// TODO: Add a launch button when a relevant file is open
2622
const config = workspace.getConfiguration('processing');
2723

@@ -115,6 +111,38 @@ export async function activate(context: ExtensionContext) {
115111
console.log(e);
116112
};
117113

114+
115+
const runSketch = commands.registerCommand('processing.sketch.run', (resource: Uri) => {
116+
if (!resource) {
117+
return;
118+
}
119+
120+
// Create a new terminal
121+
if (terminal === undefined) {
122+
terminal = window.createTerminal("Sketch");
123+
}
124+
125+
// Show the terminal panel
126+
terminal.show(true);
127+
128+
// Send the command to the terminal
129+
terminal.sendText(`${selectedVersion.path} cli --sketch=${dirname(resource.fsPath)} --run`, true);
130+
131+
// clear the terminal
132+
terminal.sendText("clear", true);
133+
});
134+
135+
const stopSketch = commands.registerCommand('processing.sketch.stop', () => {
136+
if (terminal === undefined) {
137+
return;
138+
}
139+
140+
// Send the command to the terminal
141+
terminal.sendText('\x03', false);
142+
});
143+
144+
context.subscriptions.push(runSketch, stopSketch);
145+
118146
// Start the client. This will also launch the server
119147
client.start();
120148
}

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,42 @@
2121
],
2222
"main": "./client/out/extension",
2323
"contributes": {
24+
"commands": [
25+
{
26+
"command": "processing.sketch.run",
27+
"title": "Run the Processing Sketch",
28+
"icon": "$(play)"
29+
},
30+
{
31+
"command": "processing.sketch.stop",
32+
"title": "Stop the Processing Sketch",
33+
"icon": "$(stop)"
34+
}
35+
],
36+
"menus": {
37+
"editor/title": [
38+
{
39+
"command": "processing.sketch.run",
40+
"when": "editorLangId == Processing || editorLangId == java",
41+
"group": "navigation"
42+
},
43+
{
44+
"command": "processing.sketch.stop",
45+
"when": "editorLangId == Processing || editorLangId == java",
46+
"group": "navigation"
47+
}
48+
],
49+
"terminal/context": [
50+
{
51+
"command": "processing.sketch.run",
52+
"group": "navigation"
53+
},
54+
{
55+
"command": "processing.sketch.stop",
56+
"group": "navigation"
57+
}
58+
]
59+
},
2460
"configuration": {
2561
"type": "object",
2662
"title": "Processing",

0 commit comments

Comments
 (0)