From dcfc5d77779117616503c31fc03f36841e25a3f9 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Fri, 24 May 2019 00:56:32 -0400 Subject: Added basic repl page --- src/debug/Repl.tsx | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/debug/Repl.tsx (limited to 'src/debug/Repl.tsx') diff --git a/src/debug/Repl.tsx b/src/debug/Repl.tsx new file mode 100644 index 000000000..16aef1925 --- /dev/null +++ b/src/debug/Repl.tsx @@ -0,0 +1,58 @@ +import * as React from 'react'; +import * as ReactDOM from 'react-dom'; +import { observer } from 'mobx-react'; +import { observable, computed } from 'mobx'; +import { CompileScript } from '../client/util/Scripting'; + +@observer +class Repl extends React.Component { + @observable text: string = ""; + + @observable executedCommands: { command: string, result: any }[] = []; + + onChange = (e: React.ChangeEvent) => { + this.text = e.target.value; + } + + onKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + const script = CompileScript(this.text, { addReturn: true, typecheck: false }); + if (!script.compiled) { + this.executedCommands.push({ command: this.text, result: "Compile Error" }); + } else { + const result = script.run(); + if (result.success) { + this.executedCommands.push({ command: this.text, result: result.result }); + } else { + this.executedCommands.push({ command: this.text, result: result.error }); + } + } + this.text = ""; + } + } + + @computed + get commands() { + return this.executedCommands.map(command => { + return ( +
+

{command.command}

+

{JSON.stringify(command.result)}

+
+ ); + }); + } + + render() { + return ( +
+
+ {this.commands} +
+ +
+ ); + } +} + +ReactDOM.render(, document.getElementById("root")); \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 568a3907a1277259eb9a0a5ae62cfcf5d7e60bf2 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Fri, 24 May 2019 01:11:23 -0400 Subject: Fixed firefox user select stuff Made repl multi-line --- src/client/views/Main.scss | 3 +++ src/debug/Repl.tsx | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/debug/Repl.tsx') diff --git a/src/client/views/Main.scss b/src/client/views/Main.scss index 385298e18..57a53c999 100644 --- a/src/client/views/Main.scss +++ b/src/client/views/Main.scss @@ -15,6 +15,9 @@ body { div { user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; } #dash-title { diff --git a/src/debug/Repl.tsx b/src/debug/Repl.tsx index 16aef1925..ef00ed466 100644 --- a/src/debug/Repl.tsx +++ b/src/debug/Repl.tsx @@ -10,12 +10,12 @@ class Repl extends React.Component { @observable executedCommands: { command: string, result: any }[] = []; - onChange = (e: React.ChangeEvent) => { + onChange = (e: React.ChangeEvent) => { this.text = e.target.value; } onKeyDown = (e: React.KeyboardEvent) => { - if (e.key === "Enter") { + if (e.ctrlKey && e.key === "Enter") { const script = CompileScript(this.text, { addReturn: true, typecheck: false }); if (!script.compiled) { this.executedCommands.push({ command: this.text, result: "Compile Error" }); @@ -49,7 +49,7 @@ class Repl extends React.Component {
{this.commands}
- +