-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39659ff
commit fe8a06a
Showing
10 changed files
with
628 additions
and
31 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/>) | ||
} |
Oops, something went wrong.