File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed
Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,12 @@ import {
44 useState ,
55 useEffect ,
66 useCallback ,
7+ useMemo ,
78} from "react" ;
89import Spinner from "react-bootstrap/Spinner" ;
910
1011import { parse } from "yaml" ;
12+ import { LogProcessor } from "./logProcessor.js" ;
1113
1214const CATALOGS = [
1315 "https://raw.githubusercontent.com/dockersamples/awesome-labspaces/refs/heads/main/catalog.yaml" ,
@@ -30,6 +32,8 @@ export function DockerContextProvider({ children }) {
3032 const [ launchLog , setLaunchLog ] = useState ( "" ) ;
3133 const [ forceRefreshCount , setForceRefreshCount ] = useState ( 0 ) ;
3234
35+ const logProcessor = useMemo ( ( ) => new LogProcessor ( ) , [ ] ) ;
36+
3337 useEffect ( ( ) => {
3438 Promise . all (
3539 CATALOGS . map ( ( url ) =>
@@ -92,6 +96,7 @@ export function DockerContextProvider({ children }) {
9296 const startLabspace = useCallback (
9397 ( location ) => {
9498 console . log ( `Starting Labspace with location ${ location } ` ) ;
99+ logProcessor . reset ( ) ;
95100 setLaunchLog ( "" ) ;
96101 setStartingLabspace ( location ) ;
97102
@@ -110,7 +115,13 @@ export function DockerContextProvider({ children }) {
110115 stream : {
111116 onOutput ( data ) {
112117 const newData = data . stdout ? data . stdout : data . stderr ;
113- setLaunchLog ( ( l ) => l + newData ) ;
118+ let result ;
119+ newData . split ( "\n" ) . forEach ( ( line ) => {
120+ if ( line . trim ( ) === "" ) return ;
121+
122+ result = logProcessor . processLine ( line . trim ( ) ) ;
123+ } ) ;
124+ setLaunchLog ( result ) ;
114125 } ,
115126 onClose ( exitCode ) {
116127 setHasLabspace ( true ) ;
Original file line number Diff line number Diff line change 1+ export class LogProcessor {
2+ constructor ( ) {
3+ this . lines = [ ] ;
4+ this . identifierToLineMapping = new Map ( ) ;
5+
6+ this . downloadPattern = / ^ ( .+ ?) \s + ( P u l l | D o w n l o a d | E x t r a c t i n g ) / ;
7+ this . resourceCreationPattern = / ( C o n t a i n e r | V o l u m e ) \s + ( [ a - z 0 - 9 - ] + ) \s + / ;
8+ }
9+
10+ reset ( ) {
11+ this . lines = [ ] ;
12+ this . identifierToLineMapping = new Map ( ) ;
13+ }
14+
15+ processLine ( line ) {
16+ const downloadMatch = line . match ( this . downloadPattern ) ;
17+
18+ if ( downloadMatch ) {
19+ const identifier = downloadMatch [ 1 ] . trim ( ) ;
20+
21+ if ( this . identifierToLineMapping . has ( identifier ) ) {
22+ this . lines [ this . identifierToLineMapping . get ( identifier ) ] = line ;
23+ } else {
24+ this . identifierToLineMapping . set ( identifier , this . lines . length ) ;
25+ this . lines . push ( line ) ;
26+ }
27+ } else if ( this . resourceCreationPattern . test ( line ) ) {
28+ const identifier = line . match ( this . resourceCreationPattern ) [ 2 ] ;
29+ if ( this . identifierToLineMapping . has ( identifier ) ) {
30+ this . lines [ this . identifierToLineMapping . get ( identifier ) ] = line ;
31+ } else {
32+ this . identifierToLineMapping . set ( identifier , this . lines . length ) ;
33+ this . lines . push ( line ) ;
34+ }
35+ } else {
36+ this . lines . push ( line ) ;
37+ }
38+
39+ return this . lines . join ( "\n" ) ;
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments