-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyRepl.tsx
41 lines (38 loc) · 1.1 KB
/
PyRepl.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from "react";
import { pyTerminalExists, scrollToPyTerminal } from "../utils/pyscript";
type PyReplProps = {
code: string;
};
const PyRepl: React.FC<PyReplProps> = ({ code }) => {
const random = Math.random().toString(32).substring(2);
const outputId = `py-output-${random}`;
// @ts-ignore
const pyRepl = <py-repl output={outputId}>{code}</py-repl>;
const outputDescription = pyTerminalExists() ? (
<>
出力はターミナルを確認してください。
<a
style={{ color: "inherit", cursor: "pointer" }}
onClick={scrollToPyTerminal}
>
ターミナルの位置に移動
</a>
</>
) : null;
return (
<>
<style>{`
.py-repl-run-button {opacity: 1;}
`}</style>
<div className="mb-5">
▶ボタンをクリックして実行します。書き換えることもできます!
</div>
{pyRepl}
<pre id={outputId}></pre>
<small style={{ whiteSpace: "pre-wrap" }}>
WebAssembly で実行されます。{outputDescription}
</small>
</>
);
};
export default PyRepl;