Terminal Ext
syspwda opened this issue · comments
BRAINSONTHECRUB commented
import React from "react";
import { Page, Ansi } from "@mmrl/ui";
import { Stack } from "@mui/material";
import { StringsProvider } from "@mmrl/providers";
import { useStrings } from "@mmrl/hooks";
const strs = {
en: {
hello: "\x1b[36mHello\x1b[0m"
},
de: {
hello: "Hallo"
}
}
const Config = () => {
const [lines, setLines] = React.useState([])
const processCommand = (rawCommand) => {
let arg;
let command;
console.log(rawCommand)
const i = rawCommand.indexOf(' ');
if (i != -1 && rawCommand.length != i + 1) {
arg = rawCommand.substring(i + 1).trim().split(" ")
command = rawCommand.substring(0, i)
} else {
arg = ""
command = rawCommand
}
switch (command) {
case "clearTerminal":
setLines([]);
break;
case "log":
console.log(arg[0])
break;
}
}
const onPrint = (s) => {
if (s.startsWith("#!mmrl:")) {
processCommand(s.substring(7));
} else {
return s
}
}
React.useEffect(() => {
setLines([
"#!mmrl:log 4 ddd d",
"sdfsddfghfghfgh",
"df\x1b[36mHello\x1b[0mfgffgnhnfgh",
"fgdfgsff"
])
}, [])
return (
<Page>
<Stack>
{lines.map((line) => <Ansi style={{ display: "inline-block" }}>{onPrint(line)}</Ansi>)}
</Stack>
</Page>
)
}
const Main = () => {
return (
<StringsProvider data={strs}>
<Config />
</StringsProvider>
)
}
export default Main
if [ -f "/system/etc/mmrl.sh" ]; then
mmrl() {
ui_print "$(echo "#!mmrl:$@")"
}
else
mmrl() { true; }
fi