@@ -61,6 +61,7 @@ export class FileOps {
61
61
let error = this . _repl . getErrorOutput ( ) ;
62
62
if ( error ) {
63
63
console . error ( "Python Error - " + error . type + ": " + error . message ) ;
64
+ this . _repl . writeErrorToTerminal ( error . raw ) ;
64
65
if ( error . type == "OSError" && error . errno == 30 ) {
65
66
this . _isReadOnly = true ;
66
67
// Throw an error if needed
@@ -228,7 +229,7 @@ for item in contents:
228
229
try:
229
230
import storage
230
231
print(storage.getmount("/").readonly)
231
- except:
232
+ except ImportError :
232
233
print(False)
233
234
` ;
234
235
let result = await this . _repl . runCode ( code ) ;
@@ -411,6 +412,10 @@ export class REPL {
411
412
}
412
413
}
413
414
415
+ writeErrorToTerminal ( data ) {
416
+ this . writeToTerminal ( `\x1b[91m${ data } \x1b[0m` ) ;
417
+ }
418
+
414
419
_sleep ( ms ) {
415
420
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
416
421
}
@@ -457,7 +462,6 @@ export class REPL {
457
462
let lastRawPosition = this . _findLastRegexPosition ( rawModRegex , buffer ) ;
458
463
let lastNormalPosition = this . _findLastRegexPosition ( normalModRegex , buffer ) ;
459
464
let lastPrePromptPosition = this . _findLastRegexPosition ( prePromptRegex , buffer ) ;
460
-
461
465
if ( lastPrePromptPosition > lastNormalPosition && lastPrePromptPosition > lastRawPosition ) {
462
466
this . _mode = MODE_PRE_PROMPT ;
463
467
if ( DEBUG ) {
@@ -533,7 +537,7 @@ export class REPL {
533
537
if ( this . _rawByteCount >= 2 ) {
534
538
while ( bytes . length > 0 ) {
535
539
if ( this . _checkpointCount == 0 ) {
536
- if ( bytes . slice ( 0 , 2 ) . match ( "OK" ) ) {
540
+ if ( bytes . slice ( 0 , 2 ) . match ( "OK" ) || bytes . slice ( 0 , 3 ) . match ( ">OK" ) ) {
537
541
this . _checkpointCount ++ ;
538
542
bytes = bytes . slice ( 2 ) ;
539
543
} else if ( bytes . slice ( 0 , 2 ) . match ( "ra" ) ) {
@@ -662,7 +666,7 @@ export class REPL {
662
666
await this . serialTransmit ( keySequence ) ;
663
667
}
664
668
await this . _detectCurrentMode ( ) ;
665
- await this . _sleep ( 100 ) ;
669
+ await this . _sleep ( 250 ) ;
666
670
}
667
671
} , 3000
668
672
) ;
@@ -774,8 +778,8 @@ export class REPL {
774
778
}
775
779
776
780
// Allows for supplied python code to be run on the device via the REPL in normal mode
777
- async runCode ( code , codeTimeoutMs = CODE_EXECUTION_TIMEOUT ) {
778
- this . terminalOutput = DEBUG ;
781
+ async runCode ( code , codeTimeoutMs = CODE_EXECUTION_TIMEOUT , showOutput = false ) {
782
+ this . terminalOutput = DEBUG || showOutput ;
779
783
780
784
await this . getToPrompt ( ) ;
781
785
let result = await this . execRawMode ( code + LINE_ENDING_LF , codeTimeoutMs ) ;
0 commit comments