forked from OpenDevin/OpenDevin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jupyter.tsx
77 lines (71 loc) · 2.59 KB
/
Jupyter.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from "react";
import { useSelector } from "react-redux";
import SyntaxHighlighter from "react-syntax-highlighter";
import Markdown from "react-markdown";
import { atomOneDark } from "react-syntax-highlighter/dist/esm/styles/hljs";
import { RootState } from "#/store";
import { Cell } from "#/state/jupyterSlice";
interface IJupyterCell {
cell: Cell;
}
function JupyterCell({ cell }: IJupyterCell): JSX.Element {
const code = cell.content;
if (cell.type === "input") {
return (
<div className="rounded-lg bg-gray-800 dark:bg-gray-900 p-2 text-xs">
<div className="mb-1 text-gray-400">EXECUTE</div>
<pre
className="scrollbar-custom scrollbar-thumb-gray-500 hover:scrollbar-thumb-gray-400 dark:scrollbar-thumb-white/10 dark:hover:scrollbar-thumb-white/20 overflow-auto px-5"
style={{ padding: 0, marginBottom: 0, fontSize: "0.75rem" }}
>
<SyntaxHighlighter language="python" style={atomOneDark}>
{code}
</SyntaxHighlighter>
</pre>
</div>
);
}
return (
<div className="rounded-lg bg-gray-800 dark:bg-gray-900 p-2 text-xs">
<div className="mb-1 text-gray-400">STDOUT/STDERR</div>
<pre
className="scrollbar-custom scrollbar-thumb-gray-500 hover:scrollbar-thumb-gray-400 dark:scrollbar-thumb-white/10 dark:hover:scrollbar-thumb-white/20 overflow-auto px-5 max-h-[60vh] bg-gray-800"
style={{ padding: 0, marginBottom: 0, fontSize: "0.75rem" }}
>
{/* split code by newline and render each line as a plaintext, except it starts with `![image]` so we render it as markdown */}
{code.split("\n").map((line, index) => {
if (line.startsWith("![image](data:image/png;base64,")) {
// add new line before and after the image
return (
<div key={index}>
<Markdown urlTransform={(value: string) => value}>
{line}
</Markdown>
<br />
</div>
);
}
return (
<div key={index}>
<SyntaxHighlighter language="plaintext" style={atomOneDark}>
{line}
</SyntaxHighlighter>
<br />
</div>
);
})}
</pre>
</div>
);
}
function Jupyter(): JSX.Element {
const { cells } = useSelector((state: RootState) => state.jupyter);
return (
<div className="flex-1 overflow-y-auto flex flex-col">
{cells.map((cell, index) => (
<JupyterCell key={index} cell={cell} />
))}
</div>
);
}
export default Jupyter;