Skip to content

Commit c1cc4ee

Browse files
committed
분기처리 언어별로
1 parent 5d02071 commit c1cc4ee

2 files changed

Lines changed: 56 additions & 31 deletions

File tree

packages/frontend/src/features/courses/LessonPage.tsx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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 [];

packages/frontend/src/features/courses/components/mobile/MobileLessonView.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,36 @@ export function MobileLessonView({
9898
currentStepIndex
9999
);
100100

101-
// 터미널 출력 라인 변환 (C/Java/Python 모두 지원)
101+
// 터미널 출력 라인 변환 — languageId 기반 분기
102102
const terminalLines = useMemo((): TerminalLine[] => {
103-
// 1. stdout 우선 (C, Java)
104-
if (currentStep?.stdout) {
105-
return currentStep.stdout
106-
.split('\n')
107-
.filter(Boolean)
103+
if (!currentStep) return [];
104+
105+
// C: step.stdout (누적 문자열)
106+
if (languageId === 'c') {
107+
if (!currentStep.stdout) return [];
108+
return currentStep.stdout.split('\n').filter(Boolean)
108109
.map((line): TerminalLine => ({ content: line, type: 'stdout' }));
109110
}
110111

111-
// 2. Python: pythonMemoryState.output
112-
const pythonOutput = (currentStep as any)?.pythonMemoryState?.output;
113-
if (Array.isArray(pythonOutput)) {
114-
return pythonOutput.map((line): TerminalLine => ({
115-
content: String(line),
116-
type: 'stdout'
117-
}));
112+
// Python: pythonMemoryState.output (배열)
113+
if (languageId === 'python' || languageId === 'python-practical') {
114+
const output = (currentStep as any)?.pythonMemoryState?.output;
115+
if (!Array.isArray(output)) return [];
116+
return output.map((line): TerminalLine => ({ content: String(line), type: 'stdout' }));
117+
}
118+
119+
// Java: javaMemoryState.output (배열)
120+
if (languageId === 'java') {
121+
const output = (currentStep as any)?.javaMemoryState?.output;
122+
if (!Array.isArray(output)) return [];
123+
return output.map((line): TerminalLine => ({ content: String(line), type: 'stdout' }));
124+
}
125+
126+
// JavaScript: eventLoopState.output (배열)
127+
if (languageId === 'javascript' || languageId === 'js') {
128+
const output = (currentStep as any)?.eventLoopState?.output;
129+
if (!Array.isArray(output)) return [];
130+
return output.map((line): TerminalLine => ({ content: String(line), type: 'stdout' }));
118131
}
119132

120133
return [];

0 commit comments

Comments
 (0)