This repository was archived by the owner on Oct 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -752,7 +752,28 @@ export class ArduinoApp {
752
752
}
753
753
return ret ;
754
754
}
755
- const stdoutcb = ( line : string ) => {
755
+
756
+ // Wrap line-oriented callbacks to accept arbitrary chunks of data.
757
+ const wrapLineCallback = ( callback : ( line : string ) => void ) => {
758
+ let buffer = "" ;
759
+ let startIndex = 0 ;
760
+ return ( data : string ) => {
761
+ buffer += data ;
762
+ while ( true ) {
763
+ const pos = buffer . indexOf ( os . EOL , startIndex ) ;
764
+ if ( pos < 0 ) {
765
+ startIndex = buffer . length ;
766
+ break ;
767
+ }
768
+ const line = buffer . substring ( 0 , pos + os . EOL . length ) ;
769
+ buffer = buffer . substring ( pos + os . EOL . length ) ;
770
+ startIndex = 0 ;
771
+ callback ( line ) ;
772
+ }
773
+ } ;
774
+ }
775
+
776
+ const stdoutcb = wrapLineCallback ( ( line : string ) => {
756
777
if ( cocopa . callback ) {
757
778
cocopa . callback ( line ) ;
758
779
}
@@ -764,8 +785,8 @@ export class ArduinoApp {
764
785
arduinoChannel . channel . append ( line ) ;
765
786
}
766
787
}
767
- }
768
- const stderrcb = ( line : string ) => {
788
+ } ) ;
789
+ const stderrcb = wrapLineCallback ( ( line : string ) => {
769
790
if ( os . platform ( ) === "win32" ) {
770
791
line = line . trim ( ) ;
771
792
if ( line . length <= 0 ) {
@@ -792,7 +813,7 @@ export class ArduinoApp {
792
813
}
793
814
}
794
815
arduinoChannel . channel . append ( line ) ;
795
- }
816
+ } ) ;
796
817
797
818
return await util . spawn (
798
819
this . _settings . commandPath ,
You can’t perform that action at this time.
0 commit comments