Commit fde1f778 authored by yann300's avatar yann300

allow running js from the CLI

parent ad374eb2
...@@ -475,6 +475,20 @@ class Terminal extends Plugin { ...@@ -475,6 +475,20 @@ class Terminal extends Plugin {
return self._view.el return self._view.el
function wrapScript (script) {
return `
try {
const ret = ${script};
if (ret instanceof Promise) {
ret.then((result) => { console.log(result) }).catch((error) => { console.log(error) })
} else {
console.log(ret)
}
} catch (e) {
console.log(error)
}
`
}
function change (event) { function change (event) {
if (self._components.autoCompletePopup.handleAutoComplete( if (self._components.autoCompletePopup.handleAutoComplete(
event, event,
...@@ -494,7 +508,7 @@ class Terminal extends Plugin { ...@@ -494,7 +508,7 @@ class Terminal extends Plugin {
self._view.input.innerText = '\n' self._view.input.innerText = '\n'
if (script.length) { if (script.length) {
self._cmdHistory.unshift(script) self._cmdHistory.unshift(script)
self.commands.script(script) self.commands.script(wrapScript(script))
} }
self._components.autoCompletePopup.removeAutoComplete() self._components.autoCompletePopup.removeAutoComplete()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment