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-
61import { 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
105import {
116 Executable ,
@@ -20,8 +15,9 @@ interface ProcessingVersion {
2015 path : string ;
2116}
2217
18+ let terminal : Terminal | undefined ;
19+
2320export 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}
0 commit comments