Skip to content

Commit 85f47a8

Browse files
committed
writeOutput()の改行処理を修正
1 parent ed541cd commit 85f47a8

File tree

3 files changed

+37
-50
lines changed

3 files changed

+37
-50
lines changed

app/terminal/exec.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export function ExecFile(props: ExecProps) {
5858
// Append only the new output
5959
writeOutput(
6060
terminalInstanceRef.current!,
61-
[output],
62-
true,
61+
output,
6362
undefined,
6463
null, // ファイル実行で"return"メッセージが返ってくることはないはずなので、Prismを渡す必要はない
6564
props.language

app/terminal/repl.tsx

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import { useEmbedContext } from "./embedContext";
1717
import { emptyMutex, langConstants, RuntimeLang, useRuntime } from "./runtime";
1818
import clsx from "clsx";
1919

20-
export type ReplOutputType = "stdout" | "stderr" | "error" | "return" | "trace" | "system";
20+
export type ReplOutputType =
21+
| "stdout"
22+
| "stderr"
23+
| "error"
24+
| "return"
25+
| "trace"
26+
| "system";
2127
export interface ReplOutput {
2228
type: ReplOutputType; // 出力の種類
2329
message: string; // 出力メッセージ
@@ -30,47 +36,37 @@ export type SyntaxStatus = "complete" | "incomplete" | "invalid"; // 構文チ
3036

3137
export function writeOutput(
3238
term: Terminal,
33-
outputs: ReplOutput[],
34-
endNewLine: boolean,
39+
output: ReplOutput,
3540
returnPrefix: string | undefined,
3641
Prism: typeof import("prismjs") | null,
3742
language: RuntimeLang
3843
) {
39-
for (let i = 0; i < outputs.length; i++) {
40-
const output = outputs[i];
41-
if (i > 0) {
42-
term.writeln("");
43-
}
44-
// 出力内容に応じて色を変える
45-
const message = String(output.message).replace(/\n/g, "\r\n");
46-
switch (output.type) {
47-
case "error":
48-
term.write(chalk.red(message));
49-
break;
50-
case "trace":
51-
term.write(chalk.blue.italic(message));
52-
break;
53-
case "system":
54-
term.write(systemMessageColor(message));
55-
break;
56-
case "return":
57-
if (returnPrefix) {
58-
term.write(returnPrefix);
59-
}
60-
if (Prism) {
61-
term.write(highlightCodeToAnsi(Prism, message, language));
62-
} else {
63-
console.warn("Prism is not loaded, cannot highlight return value");
64-
term.write(message);
65-
}
66-
break;
67-
default:
68-
term.write(message);
69-
break;
70-
}
71-
}
72-
if (endNewLine && outputs.length > 0) {
73-
term.writeln("");
44+
// 出力内容に応じて色を変える
45+
const message = String(output.message).replace(/\n/g, "\r\n");
46+
switch (output.type) {
47+
case "error":
48+
term.writeln(chalk.red(message));
49+
break;
50+
case "trace":
51+
term.writeln(chalk.blue.italic(message));
52+
break;
53+
case "system":
54+
term.writeln(systemMessageColor(message));
55+
break;
56+
case "return":
57+
if (returnPrefix) {
58+
term.write(returnPrefix);
59+
}
60+
if (Prism) {
61+
term.writeln(highlightCodeToAnsi(Prism, message, language));
62+
} else {
63+
console.warn("Prism is not loaded, cannot highlight return value");
64+
term.writeln(message);
65+
}
66+
break;
67+
default:
68+
term.writeln(message);
69+
break;
7470
}
7571
}
7672

@@ -180,8 +176,7 @@ export function ReplTerminal({
180176
if (terminalInstanceRef.current) {
181177
writeOutput(
182178
terminalInstanceRef.current,
183-
[output],
184-
false,
179+
output,
185180
returnPrefix,
186181
Prism,
187182
language
@@ -219,17 +214,12 @@ export function ReplTerminal({
219214
const command = inputBuffer.current.join("\n").trim();
220215
inputBuffer.current = [];
221216
const collectedOutputs: ReplOutput[] = [];
222-
let isFirstOutput = true;
223217
await runtimeMutex.runExclusive(async () => {
224218
await runCommand(command, (output) => {
225219
collectedOutputs.push(output);
226220
handleOutput(output);
227-
isFirstOutput = false;
228221
});
229222
});
230-
if (!isFirstOutput && terminalInstanceRef.current) {
231-
terminalInstanceRef.current.writeln("");
232-
}
233223
updateBuffer(() => [""]);
234224
addReplOutput?.(terminalId, command, collectedOutputs);
235225
}
@@ -311,7 +301,6 @@ export function ReplTerminal({
311301
for (const output of cmd.output) {
312302
handleOutput(output);
313303
}
314-
terminalInstanceRef.current!.writeln("");
315304
updateBuffer(() => [""]);
316305
}
317306
} else {
@@ -352,7 +341,6 @@ export function ReplTerminal({
352341
for (const output of cmd.output) {
353342
handleOutput(output);
354343
}
355-
terminalInstanceRef.current!.writeln("");
356344
updateBuffer(() => [""]);
357345
}
358346
}

app/terminal/wandbox/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export async function compileAndRun(
164164
ndjsonType: r.type,
165165
output: {
166166
type: "system",
167-
message: `ステータス ${result.status} で異常終了しました`,
167+
message: `ステータス ${r.data} で異常終了しました`,
168168
}
169169
})
170170
}

0 commit comments

Comments
 (0)