Skip to content

Commit 7a23eb0

Browse files
Merge pull request #63 from cesare-montresor/main (#64)
Fix apiConnect file write reset
1 parent a96d79e commit 7a23eb0

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

src/app/widgets/code-editor/code-editor/code-editor.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="tal-code-editor-header">
2323
<tal-execbar-widget #execBar
2424
(onStop)="stopAll()"
25-
(onRun)="runProject()"
25+
(onRun)="runProjectLocal()"
2626
(onConnect)="runConnectAPI()"
2727
[selectedFile]="selectedFile">
2828
</tal-execbar-widget>

src/app/widgets/code-editor/code-editor/code-editor.component.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class CodeEditorComponent implements OnInit {
3636
public selectedService?: ServiceDescriptor;
3737
public pyodideState = CompilerState.Unknown
3838
public pyodideStateContent? = ""
39+
public apiRun = false
3940

4041
public fsroot = FsService.EmptyFolder;
4142
public fslist: FsNodeList = [];
@@ -120,10 +121,15 @@ export class CodeEditorComponent implements OnInit {
120121
if (state == CompilerState.Ready){
121122
this.didStateChangeReady(content)
122123
}
124+
if (state == CompilerState.Success || state == CompilerState.Error || state == CompilerState.Killed){
125+
this.apiConnectReset();
126+
}
123127
this.pyodideState=state
124128
this.pyodideStateContent=content
125129
console.log("CodeEditorComponent:didStateChange:", state)
126-
this.outputWidget.didStateChange(state,content)
130+
if(!this.apiRun || state != CompilerState.Stdin) {
131+
this.outputWidget.didStateChange(state,content)
132+
}
127133
}
128134

129135
public didStdout(data:string){
@@ -151,7 +157,7 @@ export class CodeEditorComponent implements OnInit {
151157
this.outputWidget.print(msgs[i],fromAPI?OutputType.STDINAPI:OutputType.STDIN)
152158
this.project?.driver.sendStdin(msgs[i])
153159
}
154-
if (fromAPI || this.pyodideState != CompilerState.Stdin ){
160+
if (!fromAPI || this.pyodideState != CompilerState.Stdin ){
155161
this.outputWidget.enableStdin(false)
156162
}
157163
}
@@ -232,6 +238,7 @@ export class CodeEditorComponent implements OnInit {
232238
}
233239

234240
async stopAll(){
241+
this.apiRun = false
235242
console.log("stopAll:")
236243

237244
if(this.cmdConnect){this.cmdConnect.tal.closeConnection()}
@@ -241,7 +248,13 @@ export class CodeEditorComponent implements OnInit {
241248
}
242249

243250
//-------------- API CONNECT
244-
public async runProject(useAPI = false){
251+
public async runProjectLocal(){
252+
this.apiRun = false
253+
await this.runProject();
254+
this.apiRun = false
255+
}
256+
257+
public async runProject(){
245258
console.log("runProject:")
246259
this.outputWidget.clearOutput()
247260

@@ -265,16 +278,24 @@ export class CodeEditorComponent implements OnInit {
265278

266279

267280
public async runConnectAPI(){
281+
this.apiRun = true
268282
this.outputWidget.clearOutput()
269283
this.saveFile();
270284

271285

272-
this.apiConnect().then(()=>{
273-
//TODO: on success, new files are downloaded
274-
//this.fileExplorer.refreshRoot()
275-
})
286+
await this.apiConnect()
287+
288+
this.apiRun = false
289+
this.fileExplorer.refreshRoot()
276290
}
277291

292+
async apiConnectReset(){
293+
this.current_output_file = undefined;
294+
this.cmdConnect = undefined;
295+
this.outputWidget.enableStdin(false)
296+
console.log("apiConnect:didConnectData:cmdConnect:", this.cmdConnect);
297+
}
298+
278299

279300
async apiConnect(){
280301
console.log("apiConnect")
@@ -285,6 +306,7 @@ export class CodeEditorComponent implements OnInit {
285306
}
286307
console.log("apiConnect:service:ok")
287308

309+
288310

289311
let config = await this.compiler.readConfig()
290312
if (!config){return false}
@@ -376,8 +398,8 @@ export class CodeEditorComponent implements OnInit {
376398
this.output_files = message;
377399
}
378400
else {
379-
this.cmdConnect = undefined;
380-
console.log("apiConncect:cmdConnect:value:", this.cmdConnect);
401+
this.apiConnectReset();
402+
console.log("apiConnect:didConnectClose:cmdConnect:", this.cmdConnect);
381403
}
382404
}
383405

@@ -388,9 +410,9 @@ export class CodeEditorComponent implements OnInit {
388410
this.project?.driver.writeFile("/" + this.current_output_file, data)
389411
};
390412
if(this.current_output_file === this.output_files[this.output_files.length - 1]){
391-
this.cmdConnect = undefined;
413+
this.apiConnectReset();
392414
}
393-
console.log("apiConncect:cmdConnect:value:", this.cmdConnect);
415+
console.log("apiConnect:didConnectData:cmdConnect:", this.cmdConnect);
394416
}
395417
else {
396418
this.sendStdin(data, true);

src/app/widgets/code-editor/output-widget/output-widget.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ export class OutputWidgetComponent {
138138
let ipt = this.sdtinInput.nativeElement as HTMLInputElement
139139

140140
let toggleColor = (clear?:boolean)=>{
141-
if (clear) { ipt.style.borderColor == "" }
142-
else {
143-
ipt.style.borderColor = ipt.style.borderColor == "" ? color ?? "orange" : ""
141+
if (clear) {
142+
ipt.style.borderColor == ""
143+
return
144144
}
145+
146+
ipt.style.borderColor = ipt.style.borderColor == "" ? color ?? "orange" : ""
145147
}
146148

147-
if(enable && this.stdinHighlight){ return; }
148-
if(!enable && !this.stdinHighlight){ return; }
149+
//if(enable && this.stdinHighlight){ return; }
150+
//if(!enable && !this.stdinHighlight){ return; }
149151
if(enable){
152+
if (this.stdinHighlight){clearInterval(this.stdinHighlight);}
150153
this.stdinHighlight = window.setInterval(toggleColor,1000) //window.setInterval -> number; setInterval -> strange object
151154
}else{
152155
clearInterval(this.stdinHighlight);

0 commit comments

Comments
 (0)