@@ -338,15 +338,15 @@ const InteractiveTerminalDemo = () => {
338338 } )
339339
340340 const handleInput = async ( input : string ) => {
341- const newLines = [ ...terminalLines ]
342-
343- await match ( input )
341+ match ( input )
344342 . with ( 'help' , ( ) => {
345343 posthog . capture ( 'viewed demo terminal help' , {
346344 theme : colorTheme ,
347345 demo_terminal : true ,
348346 } )
349- newLines . push (
347+ setTerminalLines ( ( prev ) => [
348+ ...prev ,
349+
350350 < TerminalOutput key = { `help-${ Date . now ( ) } ` } className = "text-wrap" >
351351 { '>' } help
352352 </ TerminalOutput > ,
@@ -362,13 +362,14 @@ const InteractiveTerminalDemo = () => {
362362 get the full experience!
363363 </ b >
364364 </ p >
365- </ TerminalOutput >
366- )
365+ </ TerminalOutput > ,
366+ ] )
367367 } )
368368 . with ( P . string . includes ( 'rainbow' ) , ( ) => {
369369 posthog . capture ( 'added demo terminal rainbow' , { demo_terminal : true } )
370370 setIsRainbow ( true )
371- newLines . push (
371+ setTerminalLines ( ( prev ) => [
372+ ...prev ,
372373 < TerminalOutput key = { `rainbow-cmd-${ Date . now ( ) } ` } >
373374 { '>' } please make the hello world background rainbow-colored
374375 </ TerminalOutput > ,
@@ -380,8 +381,8 @@ const InteractiveTerminalDemo = () => {
380381 </ TerminalOutput > ,
381382 < TerminalOutput key = { `rainbow-1-${ Date . now ( ) } ` } >
382383 🌈 Added a rainbow gradient to the component!
383- </ TerminalOutput >
384- )
384+ </ TerminalOutput > ,
385+ ] )
385386 } )
386387 . with ( 'change theme' , ( ) => {
387388 const themes : PreviewTheme [ ] = [ 'terminal-y' , 'retro' , 'light' ]
@@ -395,7 +396,8 @@ const InteractiveTerminalDemo = () => {
395396 } )
396397 setPreviewTheme ( nextTheme )
397398
398- newLines . push (
399+ setTerminalLines ( ( prev ) => [
400+ ...prev ,
399401 < TerminalOutput key = { `theme-cmd-${ Date . now ( ) } ` } >
400402 { '>' } change the theme to be more { nextTheme }
401403 </ TerminalOutput > ,
@@ -413,15 +415,16 @@ const InteractiveTerminalDemo = () => {
413415 < p className = "text-green-400" >
414416 - Updated web/src/components/app.tsx
415417 </ p >
416- </ TerminalOutput >
417- )
418+ </ TerminalOutput > ,
419+ ] )
418420 } )
419421 . with (
420422 P . when ( ( s : string ) => s . includes ( 'fix' ) && s . includes ( 'bug' ) ) ,
421423 ( ) => {
422424 posthog . capture ( 'fixed demo terminal bug' , { demo_terminal : true } )
423425 setShowError ( false )
424- newLines . push (
426+ setTerminalLines ( ( prev ) => [
427+ ...prev ,
425428 < TerminalOutput key = { `fix-1-${ Date . now ( ) } ` } >
426429 < b className = "text-green-400" > Codebuff:</ b > I found a potential
427430 bug - the greeting is missing an exclamation mark.
@@ -435,46 +438,17 @@ const InteractiveTerminalDemo = () => {
435438 - Updated web/src/components/app.tsx
436439 </ p >
437440 < p className = "text-green-400" > - Created web/tailwind.config.ts</ p >
438- </ TerminalOutput >
439- )
441+ </ TerminalOutput > ,
442+ ] )
440443 setPreviewContent ( 'fixed' )
441444 }
442445 )
443446 . with ( 'clear' , ( ) => {
444447 setTerminalLines ( [ ] )
445448 } )
446- . otherwise ( async ( ) => {
447- const randomFiles = getRandomFiles ( )
448- newLines . push (
449- < TerminalOutput key = { `ask-1-${ Date . now ( ) } ` } >
450- < p >
451- { '> ' }
452- { input }
453- </ p >
454- </ TerminalOutput > ,
455- < TerminalOutput key = { `files-${ Date . now ( ) } ` } >
456- < b className = "text-green-400" > Codebuff:</ b > Reading additional
457- files...
458- { randomFiles . slice ( 0 , 3 ) . map ( ( file ) => (
459- < p key = { file } className = "text-wrap" >
460- - { file }
461- </ p >
462- ) ) }
463- { randomFiles . length > 3 && (
464- < p className = "text-wrap" >
465- and { randomFiles . length - 3 } more:{ ' ' }
466- { randomFiles . slice ( 3 ) . join ( ', ' ) }
467- </ p >
468- ) }
469- </ TerminalOutput > ,
470- < TerminalOutput key = { `ask-${ Date . now ( ) } ` } > Thinking...</ TerminalOutput >
471- )
472- setTerminalLines ( newLines )
473-
474- await demoMutation . mutateAsync ( input )
449+ . otherwise ( ( ) => {
450+ demoMutation . mutate ( input )
475451 } )
476-
477- setTerminalLines ( newLines )
478452 }
479453
480454 return (
0 commit comments