From b9732646ca5da5d3248094a9fe842867b60c3fed Mon Sep 17 00:00:00 2001 From: ankushKun Date: Sun, 4 Aug 2024 19:09:06 +0530 Subject: [PATCH] add: lua history --- .../views/components/editor/components/history.tsx | 6 +++++- .../views/components/editor/components/notebook-editor.tsx | 2 +- .../views/components/editor/components/terminal.tsx | 1 + next_app/src/components/views/components/editor/index.tsx | 1 + next_app/src/hooks/useGlobalState.ts | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/next_app/src/components/views/components/editor/components/history.tsx b/next_app/src/components/views/components/editor/components/history.tsx index d049a45..9a10789 100644 --- a/next_app/src/components/views/components/editor/components/history.tsx +++ b/next_app/src/components/views/components/editor/components/history.tsx @@ -1,5 +1,6 @@ import { useGlobalState } from "@/hooks"; import { MsgHistory } from "@/hooks/useGlobalState"; +import Ansi from "ansi-to-react"; import { ExternalLink } from "lucide-react"; import Link from "next/link"; import { useEffect } from "react"; @@ -28,7 +29,10 @@ export default function History() {
{msg.id}
-
{msg.code}
+
+
> {msg.code}
+
{typeof msg.output == "object" ? (msg.output as any).output : msg.output}
+
) }) diff --git a/next_app/src/components/views/components/editor/components/notebook-editor.tsx b/next_app/src/components/views/components/editor/components/notebook-editor.tsx index 3fe2636..8b78eff 100644 --- a/next_app/src/components/views/components/editor/components/notebook-editor.tsx +++ b/next_app/src/components/views/components/editor/components/notebook-editor.tsx @@ -170,7 +170,7 @@ const CodeCell = ({ { name: "File-Type", value: "Notebook" } ]); console.log(result); - globalState.appendHistory(project.name, { id: (result as any).id!, code: cell.code, timestamp: Date.now() }) + globalState.appendHistory(project.name, { id: (result as any).id!, code: cell.code, timestamp: Date.now(), output: result.Output.data }); // const fileContent = {...manager.getProject(project.name).getFile(file.name).content}; diff --git a/next_app/src/components/views/components/editor/components/terminal.tsx b/next_app/src/components/views/components/editor/components/terminal.tsx index 747c977..53367fb 100644 --- a/next_app/src/components/views/components/editor/components/terminal.tsx +++ b/next_app/src/components/views/components/editor/components/terminal.tsx @@ -193,6 +193,7 @@ export default function AOTerminal({ commandOutputs, setCommandOutputs }: { const result = await runLua(text, project.process, [ { name: "File-Type", value: "Terminal" } ]); + globalState.appendHistory(project.name, { id: (result as any).id!, code: text, timestamp: Date.now(), output: result.Output.data }); if (result.Error) { console.log(result.Error); diff --git a/next_app/src/components/views/components/editor/index.tsx b/next_app/src/components/views/components/editor/index.tsx index 5851ec4..32ed92a 100644 --- a/next_app/src/components/views/components/editor/index.tsx +++ b/next_app/src/components/views/components/editor/index.tsx @@ -90,6 +90,7 @@ function Editor() { { name: "File-Type", value: "Normal" } ]); console.log(result); + globalState.appendHistory(project.name, { id: (result as any).id!, code: code, timestamp: Date.now(), output: result.Output.data }); if (result.Error) { console.log(result.Error); globalState.setLastOutput("\x1b[1;31m" + result.Error as string); diff --git a/next_app/src/hooks/useGlobalState.ts b/next_app/src/hooks/useGlobalState.ts index c7ec9f1..5752eaf 100644 --- a/next_app/src/hooks/useGlobalState.ts +++ b/next_app/src/hooks/useGlobalState.ts @@ -8,6 +8,7 @@ export interface MsgHistory { code: string; id: string; timestamp: number; + output: string; } interface State {