@@ -53,12 +53,23 @@ export const useScaffold = (): Scaffold => {
5353 const [ error , setError ] = useState ( '' )
5454 const matchPID = useRef < string | undefined > ( undefined )
5555 const forceUpdate = useForceUpdate ( )
56- const consoleLines = useRef < RingBuffer < ConsoleLine > > ( new RingBuffer ( 10000 ) )
56+ const consoleLines = useRef < RingBuffer < ConsoleLine > > ( new RingBuffer ( 50000 ) )
5757
5858 const [ webSocketListener , setWebSocketListener ] = useState < WebSocketListener | undefined > ( )
5959
6060 const log = ( line : ConsoleLine ) => {
61+ // Set match index to be the same as the previous log value
62+ if ( consoleLines . current . length ( ) > 0 ) {
63+ line . matchIdx = consoleLines . current . get ( consoleLines . current . length ( ) - 1 ) ! . matchIdx
64+ }
65+
66+ // If we encounter the end-of-match message, increment the match index
67+ if ( line . content . startsWith ( '[server]' ) && line . content . includes ( 'Finished' ) ) {
68+ line . matchIdx ++
69+ }
70+
6171 consoleLines . current . push ( line )
72+
6273 forceUpdate ( )
6374 }
6475
@@ -107,7 +118,7 @@ export const useScaffold = (): Scaffold => {
107118 )
108119 matchPID . current = newPID
109120 } catch ( e : any ) {
110- consoleLines . current . push ( { content : e , type : 'error' } )
121+ consoleLines . current . push ( { content : e , type : 'error' , matchIdx : 0 } )
111122 }
112123 forceUpdate ( )
113124 }
@@ -176,15 +187,15 @@ export const useScaffold = (): Scaffold => {
176187
177188 nativeAPI . child_process . onStdout ( ( { pid, data } ) => {
178189 if ( pid !== matchPID . current ) return
179- log ( { content : data , type : 'output' } )
190+ log ( { content : data , type : 'output' , matchIdx : 0 } )
180191 } )
181192 nativeAPI . child_process . onStderr ( ( { pid, data } ) => {
182193 if ( pid !== matchPID . current ) return
183- log ( { content : data , type : 'error' } )
194+ log ( { content : data , type : 'error' , matchIdx : 0 } )
184195 } )
185196 nativeAPI . child_process . onExit ( ( { pid, code, signal } ) => {
186197 if ( pid !== matchPID . current ) return
187- log ( { content : `Exited with code ${ code } | ${ JSON . stringify ( signal ) } ` , type : 'bold' } )
198+ log ( { content : `Exited with code ${ code } | ${ JSON . stringify ( signal ) } ` , type : 'bold' , matchIdx : 0 } )
188199 matchPID . current = undefined
189200 forceUpdate ( )
190201 } )
0 commit comments