@@ -106,9 +106,11 @@ export async function readUntil(
106106 if ( port . readable && port . readableLength > 0 ) {
107107 const newData = ensureBuffer ( port . read ( 1 ) as Buffer | string | null ) ;
108108 // TODO: maybe also not relay the data if it is the suffix
109- if ( receiver && ! newData . equals ( BUFFER_04 ) && newData . length > 0 ) {
109+ if ( receiver && newData . length > 0 ) {
110110 blockCheck = false ;
111- receiver ( newData ) ;
111+ if ( ! newData . equals ( BUFFER_04 ) ) {
112+ receiver ( newData ) ;
113+ }
112114
113115 // keep normal behavior if suffix is one byte
114116 if ( suffix . length === 1 ) {
@@ -163,7 +165,8 @@ export function stopRunningStuff(
163165 // TODO: useage must be checked as most don't care about this could throw
164166 // send CTRL-C twice to stop any running program
165167 port . write (
166- "\r\x03\x03" ,
168+ // does make futer commands fail to wait for > if \r is included in this buffer
169+ Buffer . concat ( [ BUFFER_03 , BUFFER_03 ] ) ,
167170 errorCb ??
168171 ( ( err : Error | null | undefined ) : void => {
169172 if ( err ) {
@@ -192,13 +195,14 @@ export async function enterRawRepl(
192195
193196 // send CTRL-C twice to stop any running program
194197 //port.write("\r\x03\x03", errCb);
198+ port . write ( BUFFER_CR , errCb ) ;
195199 stopRunningStuff ( port , errCb ) ;
196200
197201 // flush input
198202 port . flush ( errCb ) ;
199203
200204 // enter raw repl (CTRL-A)
201- port . write ( "\r\x01" , errCb ) ;
205+ port . write ( Buffer . concat ( [ BUFFER_CR , BUFFER_01 ] ) , errCb ) ;
202206
203207 if ( softReset ) {
204208 let data =
@@ -210,7 +214,7 @@ export async function enterRawRepl(
210214 }
211215
212216 // soft reset
213- port . write ( "\x04" , errCb ) ;
217+ port . write ( BUFFER_04 , errCb ) ;
214218
215219 data =
216220 ( await readUntil ( port , 1 , "soft reboot\r\n" ) ) ?. toString ( "utf-8" ) ?? "" ;
@@ -274,8 +278,9 @@ export async function follow(
274278) : Promise < { data : string ; error : string } > {
275279 // wait for output
276280 let data =
277- ( await readUntil ( port , 1 , "\x04" , timeout , receiver ) ) ?. toString ( "utf-8" ) ??
278- "" ;
281+ ( await readUntil ( port , 1 , BUFFER_04 , timeout , receiver ) ) ?. toString (
282+ "utf-8"
283+ ) ?? "" ;
279284 if ( ! data . endsWith ( "\x04" ) ) {
280285 throw new Error ( "Error following output" ) ;
281286 }
@@ -284,7 +289,7 @@ export async function follow(
284289
285290 // wait for an error if any
286291 let error =
287- ( await readUntil ( port , 1 , "\x04" , timeout ) ) ?. toString ( "utf-8" ) ?? "" ;
292+ ( await readUntil ( port , 1 , BUFFER_04 , timeout ) ) ?. toString ( "utf-8" ) ?? "" ;
288293 if ( ! error . endsWith ( "\x04" ) ) {
289294 throw new Error ( "Error following output" ) ;
290295 }
@@ -432,7 +437,7 @@ export async function executeCommandWithoutResult(
432437 if ( useRawPasteMode ) {
433438 // try to enter raw paste mode
434439 port . write ( BUFFER_RAW_PASTE_STATUS , errCb ) ;
435- const data = await readUntil ( port , 2 , "R\x01" , 5 ) ;
440+ const data = await readUntil ( port , 2 , BUFFER_R01 , 3 ) ;
436441 if ( data ?. equals ( BUFFER_R00 ) ) {
437442 // device understood raw-paste command but doesn't support it
438443 // because it understood we don't have to manually reenter raw repl
@@ -512,7 +517,7 @@ export async function executeCommandWithResult(
512517 }
513518
514519 // call exe without result and then call follow
515- await executeCommandWithoutResult ( port , command ) ;
520+ await executeCommandWithoutResult ( port , command . trim ( ) ) ;
516521
517522 // needs to be awaited here, otherwise it will
518523 // return the promisse which will run the final block
0 commit comments