Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-laplante committed May 12, 2024
1 parent 39659ff commit fe8a06a
Show file tree
Hide file tree
Showing 10 changed files with 628 additions and 31 deletions.
259 changes: 253 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@mantine/core": "^7.9.1",
"@types/jquery": "^3.5.30",
"@types/node": "^20.12.11",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
Expand Down Expand Up @@ -67,11 +68,14 @@
"axios": "^1.6.8",
"classnames": "^2.5.1",
"immer": "^10.1.1",
"jquery": "^3.7.1",
"jquery.terminal": "^2.41.2",
"pyodide": "^0.25.1",
"react": "^18.2.0",
"react-ace": "^11.0.1",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13",
"swr": "^2.2.5",
"use-immer": "^0.9.0"
}
}
25 changes: 7 additions & 18 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import React, {useEffect, useState} from "react";

import {AppShell, Burger, createTheme, MantineColorsTuple, MantineProvider} from '@mantine/core';
import FetchWithProgress from "./FetchWithProgress";
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-jsx";
import {usePyodide} from "../usePyodide";
import {usePyodide} from "../hooks/usePyodide";
import {useDisclosure} from "@mantine/hooks";
import {useImmer} from "use-immer";
import {PlaygroundTerminal} from "./PlaygroundTerminal";

const myColor: MantineColorsTuple = [
'#e4f8ff',
Expand Down Expand Up @@ -40,13 +39,9 @@ const Inner: React.FC = () => {
useEffect(() => {
const go = async () => {
if (data && !ran) {
setRan(true);

pyodide.setStdout({
batched: (msg) => setOutput(o => { o.push(msg); })
})

console.warn("LOADING SQLITE");

await pyodide.loadPackage("sqlite3");
console.warn("LOADED!");

Expand Down Expand Up @@ -183,6 +178,7 @@ print(sys.meta_path)
console.log(d.getVar("A"));

DataSmart.destroy();
setRan(true);

} else {
console.warn(`data = ${!!data}, p = ${!!pyodide}`);
Expand All @@ -192,8 +188,9 @@ print(sys.meta_path)
go();
}, [data, pyodide, ran, setRan]);


return <>
{/*{pyodide && data && ran && <TerminalComponent pyodide={pyodide}/>}*/}

<FetchWithProgress url={"assets/bitbake-2.8.0.zip"} data={data} setData={setData}/>
<p>pyodide: {pyodideStatus}</p>
<ul>
Expand All @@ -207,7 +204,6 @@ export const App: React.FC = () => {

return (
<MantineProvider theme={theme}>

<AppShell
header={{ height: 60 }}
navbar={{
Expand All @@ -230,15 +226,8 @@ export const App: React.FC = () => {
<AppShell.Navbar p="md">Navbar</AppShell.Navbar>

<AppShell.Main>
<PlaygroundTerminal />


<AceEditor
mode="java"
theme="github"
name="UNIQUE_ID_OF_DIV"
editorProps={{$blockScrolling: true}}
/>
<Inner/>
</AppShell.Main>
</AppShell>

Expand Down
2 changes: 1 addition & 1 deletion src/components/FetchWithProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const FetchWithProgress: React.FC<FetchProgressProps> = (props: FetchProgressPro
setLoading(true);
const ret = await axios.get(props.url, {
onDownloadProgress: progressEvent => {
const percentage = Math.round(progressEvent.loaded * 100) / progressEvent.total;
const percentage = Math.round((progressEvent.loaded * 100) / progressEvent.total);
console.log(percentage);
setProgress(percentage);
},
Expand Down
68 changes: 68 additions & 0 deletions src/components/JQueryTerminal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, {useImperativeHandle, forwardRef, useRef, useEffect} from "react";
import * as $ from "jquery";
import 'jquery.terminal';
import 'jquery.terminal/css/jquery.terminal.min.css';
import {terminal} from "jquery";

interface Props {
interpreter?: TypeOrArray<JQueryTerminal.Interpreter>,
options?: JQueryTerminal.TerminalOptions
}

const BANNER = `
__ __ __ __ _____ __ __ _____ __ ___ ___ ___ _ __ __ __ __ ___ __ _ _ __ _ __
| \\ \\ | _\\ / \\_ _/ \\ /' _/_ _/__\\| _ \\ __| | _,\\ | / \\\\ \`v' // _] _ \\/__\\| || | \\| | _\\
| -< -< | v | /\\ || || /\\ |\`._\`. | || \\/ | v / _| | v_/ |_| /\\ |\`. .'| [/\\ v / \\/ | \\/ | | ' | v |
|__/__/ |__/|_||_||_||_||_||___/ |_| \\__/|_|_\\___| |_| |___|_||_| !_! \\__/_|_\\\\__/ \\__/|_|\\__|__/
Copyright (C) Agilent Technologies 2024
`;

export const JQueryTerminal: React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<unknown>> = forwardRef(function JQueryTerminal(props, ref) {
const terminalContainerRef = useRef(null);
const terminalObjectRef = useRef<JQueryTerminal>(null);

useImperativeHandle(ref, () => {
return {
echo: async (arg: string, options: JQueryTerminal.animationOptions & JQueryTerminal.EchoOptions) => {
if (terminalObjectRef.current) {
return terminalObjectRef.current.echo(arg, options);
}
},
update: (line: number, str: string) => {
terminalObjectRef.current?.update(line, str);
},
freeze: () => {
terminalObjectRef.current?.freeze(true);
terminalObjectRef.current?.set_prompt("");
},
setInterpreter: (interpreter?: TypeOrArray<JQueryTerminal.Interpreter>) => {
if (terminalObjectRef.current) {
terminalObjectRef.current.set_interpreter(interpreter);
}
}
};
}, []);

useEffect(() => {
const currentTerminal = terminalContainerRef.current;

if (currentTerminal) {
terminalObjectRef.current = $(currentTerminal).terminal(props.interpreter, {
greetings: BANNER,
...props.options
});
}

return () => {
if (currentTerminal) {
$(currentTerminal).remove();
}
if (terminalObjectRef.current) {
terminalObjectRef.current = null;
}
};
}, []);

return <div ref={terminalContainerRef} id="terminal" style={{height: '300px'}}></div>;
});
58 changes: 58 additions & 0 deletions src/components/PlaygroundTerminal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {JQueryTerminal} from "./JQueryTerminal";
import React, {useEffect, useRef} from "react";
import {usePyodide} from "../hooks/usePyodide";

import {terminal} from "jquery";
import {useEnvironmentSetup} from "../hooks/useEnvironmentSetup";

function progress(percent, width) {
var size = Math.round(width*percent/100);
var left = '', taken = '', i;
for (i=size; i--;) {
taken += '=';
}
if (taken.length > 0) {
taken = taken.replace(/=$/, '>');
}
for (i=width-size; i--;) {
left += ' ';
}
return '[' + taken + left + '] ' + percent + '%';
}

export const PlaygroundTerminal: React.FC = () => {
const terminalRef = useRef(null);

const {state} = useEnvironmentSetup();

useEffect(() => {
terminalRef.current.echo("Setting up environment");
terminalRef.current.freeze();
}, [])

useEffect(() => {
if (state.pyodideStatus === "idle") {
terminalRef.current.echo(`Pyodide: ${state.pyodideStatus}`);
terminalRef.current.echo(`Downloading bitbake: ${progress(state.bitbakeProgress, 80)}%`);
}

terminalRef.current.update(-1, `Pyodide: ${state.pyodideStatus}`);
terminalRef.current.update(-2, `Downloading bitbake: ${progress(state.bitbakeProgress, 80)}%`);
}, [state]);
//
// useEffect(() => {
// if (done && pyodide) {
// terminalRef.current.echo("Unpacking BitBake...");
// pyodide.unpackArchive(data, "zip", {
// extractDir: "bb"
// });
// terminalRef.current.echo("Done!");
// }
// }, [data, done, pyodide]);

const interpreter = (command, term) => {

};

return (<JQueryTerminal interpreter={interpreter} ref={terminalRef}/>)
}
Loading

0 comments on commit fe8a06a

Please sign in to comment.