Skip to content

Commit ea09c9d

Browse files
committed
操作可能なコードブロックとそうでないものの区別をわかりやすく
1 parent d00c06b commit ea09c9d

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

app/[docs_id]/markdown.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const components: Components = {
5353
---------------------------
5454
*/
5555
return (
56-
<div className="border border-primary m-2 rounded-lg">
56+
<div className="border border-primary border-2 shadow-md m-2 rounded-lg">
5757
<ExecFile
5858
language={match[1]}
5959
filename={match[3]}
@@ -64,7 +64,7 @@ const components: Components = {
6464
} else if (match[3]) {
6565
// ファイル名指定がある場合、ファイルエディター
6666
return (
67-
<div className="border border-primary m-2 rounded-lg">
67+
<div className="border border-primary border-2 shadow-md m-2 rounded-lg">
6868
<EditorComponent
6969
language={match[1]}
7070
tabSize={4}
@@ -80,7 +80,7 @@ const components: Components = {
8080
switch (match[1]) {
8181
case "python":
8282
return (
83-
<div className="bg-base-300 border border-primary m-2 p-4 pr-1 rounded-lg">
83+
<div className="bg-base-300 border border-primary border-2 shadow-md m-2 p-4 pr-1 rounded-lg">
8484
<PythonEmbeddedTerminal
8585
content={String(props.children || "").replace(/\n$/, "")}
8686
/>
@@ -95,7 +95,7 @@ const components: Components = {
9595
<SyntaxHighlighter
9696
language={match[1]}
9797
PreTag="div"
98-
className="border border-primary mx-2 my-2 rounded-lg text-sm! m-2! p-4! font-mono!"
98+
className="border border-base-300 mx-2 my-2 rounded-lg text-sm! m-2! p-4!"
9999
// style={todo dark theme?}
100100
{...props}
101101
>
@@ -107,7 +107,7 @@ const components: Components = {
107107
return (
108108
<SyntaxHighlighter
109109
PreTag="div"
110-
className="border border-primary mx-2 my-2 rounded-lg text-sm! m-2! p-4! font-mono!"
110+
className="border border-base-300 mx-2 my-2 rounded-lg text-sm! m-2! p-4!"
111111
// style={todo dark theme?}
112112
{...props}
113113
>

app/terminal/repl.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useRef } from "react";
44
import { highlightCodeToAnsi } from "./highlight";
55
import chalk from "chalk";
66
import { MutexInterface } from "async-mutex";
7-
import { clearTerminal, getRows, useTerminal } from "./terminal";
7+
import { clearTerminal, getRows, hideCursor, showCursor, useTerminal } from "./terminal";
88
import { useSectionCode } from "../[docs_id]/section";
99

1010
export interface ReplOutput {
@@ -88,8 +88,7 @@ export function ReplTerminal(props: ReplComponentProps) {
8888
const updateBuffer = useCallback(
8989
(newBuffer: () => string[]) => {
9090
if (terminalInstanceRef.current) {
91-
// カーソル非表示
92-
terminalInstanceRef.current.write("\x1b[?25l");
91+
hideCursor(terminalInstanceRef.current);
9392
// バッファの行数分カーソルを戻す
9493
if (inputBuffer.current.length >= 2) {
9594
terminalInstanceRef.current.write(
@@ -116,8 +115,7 @@ export function ReplTerminal(props: ReplComponentProps) {
116115
terminalInstanceRef.current.writeln("");
117116
}
118117
}
119-
// カーソルを表示
120-
terminalInstanceRef.current.write("\x1b[?25h");
118+
showCursor(terminalInstanceRef.current);
121119
}
122120
},
123121
[prompt, promptMore, language, terminalInstanceRef]
@@ -289,22 +287,24 @@ export function ReplTerminal(props: ReplComponentProps) {
289287
}, [keyHandler, termReady, runtimeReady, terminalInstanceRef]);
290288

291289
return (
292-
<div
293-
className="relative h-max"
294-
onClick={() => {
295-
if (
296-
!runtimeInitializing &&
297-
!runtimeReady &&
298-
terminalInstanceRef.current &&
299-
termReady
300-
) {
301-
initRuntime();
302-
terminalInstanceRef.current.write(
303-
chalk.dim.bold.italic("(初期化しています...しばらくお待ちください)")
304-
);
305-
}
306-
}}
307-
>
290+
<div className={"relative h-max"}>
291+
{!runtimeInitializing && !runtimeReady && (
292+
<div
293+
className="absolute z-10 inset-0 cursor-pointer"
294+
onClick={() => {
295+
if (terminalInstanceRef.current && termReady) {
296+
initRuntime();
297+
hideCursor(terminalInstanceRef.current);
298+
terminalInstanceRef.current.write(
299+
chalk.dim.bold.italic(
300+
"(初期化しています...しばらくお待ちください)"
301+
)
302+
);
303+
terminalInstanceRef.current.focus();
304+
}
305+
}}
306+
/>
307+
)}
308308
{runtimeInitializing && (
309309
<div className="absolute z-10 inset-0 cursor-wait" />
310310
)}

app/terminal/terminal.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export function clearTerminal(term: Terminal) {
4242
// term.clear();
4343
term.write("\x1b[3J\x1b[2J\x1b[1;1H");
4444
}
45+
export function hideCursor(term: Terminal) {
46+
term.write("\x1b[?25l");
47+
}
48+
export function showCursor(term: Terminal) {
49+
term.write("\x1b[?25h");
50+
}
4551

4652
interface TerminalProps {
4753
getRows?: (cols: number) => number;

public/docs/python-1.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ macOSでは、**Homebrew** というパッケージマネージャを使って
3333

3434
### ブラウザで今すぐ試す
3535

36-
このウェブサイトではこのようにドキュメント内に Python {process.env.PYODIDE_PYTHON_VERSION} のREPLが埋め込まれており、インストール不要ですぐにPythonコードを試せます。気軽に利用してください。
36+
このウェブサイトではドキュメント内に Python {process.env.PYODIDE_PYTHON_VERSION} の実行環境を埋め込んでいます。
37+
以下のように青枠で囲われたコード例には自由にPythonコードを書いて試すことができます。気軽に利用してください。
3738

3839
```python-repl
3940
>>> message = "Hello, Python!"
@@ -86,6 +87,7 @@ class str(object)
8687
## スクリプトの実行方法
8788

8889
一連の処理をまとめて実行する場合は、`.py` という拡張子を持つファイルにコードを記述します。例えば、`hello.py` というファイルを以下のように作成します。
90+
REPLでは式を入力するだけでも結果が表示されていましたが、スクリプトで結果を表示するには `print()` 関数を使う必要があります。
8991

9092
```python:hello.py
9193
print("Hello from a Python script!")
@@ -99,8 +101,6 @@ print("Hello from a Python script!")
99101
Hello from a Python script!
100102
```
101103

102-
REPLでは式を入力するだけでも結果が表示されていましたが、スクリプトで結果を表示するには `print()` 関数を使う必要があります。
103-
104104
### __main__ について
105105

106106
前述の hello.py のようにファイルの1行目から処理を書いても問題なく動作しますが、一般的には以下のようなお決まりの書き方が用いられます。

0 commit comments

Comments
 (0)