From aa8a6f7a786410fe2f60cced3325eaee510adb09 Mon Sep 17 00:00:00 2001
From: Tyler Schicke <tyler_schicke@brown.edu>
Date: Fri, 19 Jul 2019 19:23:46 -0400
Subject: Added start of REPL

---
 src/client/views/ScriptingRepl.tsx | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 src/client/views/ScriptingRepl.tsx

(limited to 'src/client/views/ScriptingRepl.tsx')

diff --git a/src/client/views/ScriptingRepl.tsx b/src/client/views/ScriptingRepl.tsx
new file mode 100644
index 000000000..bd6fc9dfb
--- /dev/null
+++ b/src/client/views/ScriptingRepl.tsx
@@ -0,0 +1,60 @@
+import * as React from 'react';
+import { observer } from 'mobx-react';
+import { observable, action } from 'mobx';
+import './ScriptingRepl.scss';
+import { Scripting, CompileScript } from '../util/Scripting';
+
+@observer
+export class ScriptingRepl extends React.Component {
+    @observable private commands: { command: string, result: any }[] = [];
+
+    @observable private commandString: string = "";
+
+    private args: any = {};
+
+    @action
+    onKeyDown = (e: React.KeyboardEvent) => {
+        if (e.key === "Enter") {
+            e.stopPropagation();
+
+            const script = CompileScript(this.commandString, { typecheck: false, addReturn: true, editable: true, params: { args: "any" } });
+            if (!script.compiled) {
+                return;
+            }
+            const result = script.run({ args: this.args });
+            if (!result.success) {
+                return;
+            }
+            this.commands.push({ command: this.commandString, result: result.result });
+
+            this.commandString = "";
+        }
+    }
+
+    @action
+    onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+        this.commandString = e.target.value;
+    }
+
+    render() {
+        return (
+            <div className="scriptingRepl-outerContainer">
+                <div className="scriptingRepl-commandsContainer">
+                    {this.commands.map(({ command, result }) => {
+                        return (
+                            <div className="scriptingRepl-resultContainer">
+                                <div className="scriptingRepl-commandString">{command}</div>
+                                <div className="scriptingRepl-commandResult">{String(result)}</div>
+                            </div>
+                        );
+                    })}
+                </div>
+                <input
+                    className="scriptingRepl-commandInput"
+                    value={this.commandString}
+                    onChange={this.onChange}
+                    onKeyDown={this.onKeyDown}></input>
+            </div>
+        );
+    }
+}
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

