Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/terminal/exec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function ExecFile(props: ExecProps) {
null, // ファイル実行で"return"メッセージが返ってくることはないはずなので、Prismを渡す必要はない
props.language
);
// TODO: 実行が完了したあとに出力された場合、embedContextのsetExecResultにも出力を追加する必要があるが、それに対応したAPIになっていない
});
// TODO: 1つのファイル名しか受け付けないところに無理やりコンマ区切りで全部のファイル名を突っ込んでいる
setExecResult(props.filenames.join(","), outputs);
Expand Down
24 changes: 19 additions & 5 deletions app/terminal/repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function ReplTerminal({

// inputBufferを更新し、画面に描画する
const updateBuffer = useCallback(
(newBuffer: () => string[]) => {
(newBuffer: (() => string[]) | null, insertBefore?: () => void) => {
if (terminalInstanceRef.current) {
hideCursor(terminalInstanceRef.current);
// バッファの行数分カーソルを戻す
Expand All @@ -142,8 +142,12 @@ export function ReplTerminal({
terminalInstanceRef.current.write("\r");
// バッファの内容をクリア
terminalInstanceRef.current.write("\x1b[0J");
// 新しいバッファの内容を表示
inputBuffer.current = newBuffer();
// バッファの前に追加で出力する内容(前のコマンドの出力)があればここで書き込む
insertBefore?.();
// 新しいバッファの内容を表示、nullなら現状維持
if (newBuffer) {
inputBuffer.current = newBuffer();
}
for (let i = 0; i < inputBuffer.current.length; i++) {
terminalInstanceRef.current.write(
(i === 0 ? prompt : (promptMore ?? prompt)) ?? "> "
Expand Down Expand Up @@ -214,12 +218,22 @@ export function ReplTerminal({
const command = inputBuffer.current.join("\n").trim();
inputBuffer.current = [];
const collectedOutputs: ReplOutput[] = [];
let executionDone = false;
await runtimeMutex.runExclusive(async () => {
await runCommand(command, (output) => {
collectedOutputs.push(output);
handleOutput(output);
if (executionDone) {
// すでに完了していて次のコマンドのプロンプトが出ている場合、その前に挿入
updateBuffer(null, () => {
handleOutput(output);
});
// TODO: embedContextのaddReplOutputにも出力を追加する必要があるが、それに対応したAPIになっていない
} else {
collectedOutputs.push(output);
handleOutput(output);
}
});
});
executionDone = true;
updateBuffer(() => [""]);
addReplOutput?.(terminalId, command, collectedOutputs);
}
Expand Down
4 changes: 0 additions & 4 deletions app/terminal/worker/jsEval.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ async function runCode(
message: `${String(e)}`,
});
}
} finally {
currentOutputCallback = null;
}

return { updatedFiles: {} as Record<string, string> };
Expand Down Expand Up @@ -126,8 +124,6 @@ function runFile(
message: `${String(e)}`,
});
}
} finally {
currentOutputCallback = null;
}

return { updatedFiles: {} as Record<string, string> };
Expand Down
4 changes: 0 additions & 4 deletions app/terminal/worker/pyodide.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ async function runCode(
message: `予期せぬエラー: ${String(e).trim()}`,
});
}
} finally {
currentOutputCallback = null;
}

const updatedFiles = readAllFiles();
Expand Down Expand Up @@ -165,8 +163,6 @@ async function runFile(
message: `予期せぬエラー: ${String(e).trim()}`,
});
}
} finally {
currentOutputCallback = null;
}

const updatedFiles = readAllFiles();
Expand Down
4 changes: 0 additions & 4 deletions app/terminal/worker/ruby.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ async function runCode(
type: "error",
message: formatRubyError(e, false),
});
} finally {
currentOutputCallback = null;
}

const updatedFiles = readAllFiles();
Expand Down Expand Up @@ -189,8 +187,6 @@ async function runFile(
type: "error",
message: formatRubyError(e, true),
});
} finally {
currentOutputCallback = null;
}

const updatedFiles = readAllFiles();
Expand Down