@@ -564,34 +564,46 @@ export function LessonPage() {
564564 // (이전 workaround 코드 제거됨 - 2026-01-27)
565565 const displayLine = currentStep ?. line || 1 ;
566566
567- // 터미널 출력 라인 변환 (C/Java/Python 모두 지원)
567+ // 터미널 출력 라인 변환 — languageId 기반 분기
568568 // 현재 스텝에서 새로 추가된 출력만 표시 (누적 X)
569569 const terminalLines = useMemo ( ( ) : TerminalLine [ ] => {
570+ if ( ! currentStep ) return [ ] ;
570571 const prevStep = navigation . currentStepIndex > 0 ? steps [ navigation . currentStepIndex - 1 ] : null ;
571572
572- // 1. stdout 우선 (C, Java)
573- if ( currentStep ?. stdout ) {
573+ // C: step.stdout (누적 문자열)
574+ if ( lang === 'c' ) {
575+ if ( ! currentStep . stdout ) return [ ] ;
574576 const currentLines = currentStep . stdout . split ( '\n' ) . filter ( Boolean ) ;
575577 const prevLines = prevStep ?. stdout ?. split ( '\n' ) . filter ( Boolean ) || [ ] ;
576-
577- // 이전 스텝 출력을 제외한 새로운 라인만 추출
578- const newLines = currentLines . slice ( prevLines . length ) ;
579-
580- return newLines . map ( ( line ) : TerminalLine => ( { content : line , type : 'stdout' } ) ) ;
578+ return currentLines . slice ( prevLines . length )
579+ . map ( ( line ) : TerminalLine => ( { content : line , type : 'stdout' } ) ) ;
581580 }
582581
583- // 2. Python: pythonMemoryState.output
584- const pythonOutput = ( currentStep as any ) ?. pythonMemoryState ?. output ;
585- if ( Array . isArray ( pythonOutput ) ) {
586- const prevPythonOutput = ( prevStep as any ) ?. pythonMemoryState ?. output || [ ] ;
582+ // Python: pythonMemoryState.output (배열)
583+ if ( lang === 'python' || lang === 'python-practical' ) {
584+ const output = ( currentStep as any ) ?. pythonMemoryState ?. output ;
585+ if ( ! Array . isArray ( output ) ) return [ ] ;
586+ const prevOutput = ( prevStep as any ) ?. pythonMemoryState ?. output || [ ] ;
587+ return output . slice ( prevOutput . length )
588+ . map ( ( line ) : TerminalLine => ( { content : String ( line ) , type : 'stdout' } ) ) ;
589+ }
587590
588- // 이전 스텝 출력을 제외한 새로운 라인만 추출
589- const newLines = pythonOutput . slice ( prevPythonOutput . length ) ;
591+ // Java: javaMemoryState.output (배열)
592+ if ( lang === 'java' ) {
593+ const output = ( currentStep as any ) ?. javaMemoryState ?. output ;
594+ if ( ! Array . isArray ( output ) ) return [ ] ;
595+ const prevOutput = ( prevStep as any ) ?. javaMemoryState ?. output || [ ] ;
596+ return output . slice ( prevOutput . length )
597+ . map ( ( line ) : TerminalLine => ( { content : String ( line ) , type : 'stdout' } ) ) ;
598+ }
590599
591- return newLines . map ( ( line ) : TerminalLine => ( {
592- content : String ( line ) ,
593- type : 'stdout'
594- } ) ) ;
600+ // JavaScript: eventLoopState.output (배열)
601+ if ( lang === 'javascript' || lang === 'js' ) {
602+ const output = ( currentStep as any ) ?. eventLoopState ?. output ;
603+ if ( ! Array . isArray ( output ) ) return [ ] ;
604+ const prevOutput = ( prevStep as any ) ?. eventLoopState ?. output || [ ] ;
605+ return output . slice ( prevOutput . length )
606+ . map ( ( line ) : TerminalLine => ( { content : String ( line ) , type : 'stdout' } ) ) ;
595607 }
596608
597609 return [ ] ;
0 commit comments