diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7529bed3..5cc8a165 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,7 +1,9 @@ name: CI on: - - pull_request - - push + pull_request: + push: + branches: + - master jobs: Test: diff --git a/lib/runtime.js b/lib/runtime.js index 5cffc2d7..c1350646 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -10,10 +10,11 @@ export default class Runtime { // Public: Initializes a new {Runtime} instance // // This class is responsible for properly configuring {Runner} - constructor(runner, codeContextBuilder, observers = []) { + constructor(runner, codeContextBuilder, observers = [], terminals = []) { this.runner = runner this.codeContextBuilder = codeContextBuilder this.observers = observers + this.terminals = terminals this.emitter = new Emitter() this.scriptOptions = this.runner.scriptOptions _.each(this.observers, (observer) => observer.observe(this)) @@ -49,11 +50,6 @@ export default class Runtime { // * "File Based" // input (Optional) - {String} that'll be provided to the `stdin` of the new process execute(argType = "Selection Based", input = null, options = null) { - if (atom.config.get("script.stopOnRerun")) { - this.stop() - } - this.emitter.emit("start") - const codeContext = this.codeContextBuilder.buildCodeContext(atom.workspace.getActiveTextEditor(), argType) // In the future we could handle a runner without the language being part @@ -65,6 +61,23 @@ export default class Runtime { const executionOptions = !options ? this.scriptOptions : options const commandContext = CommandContext.build(this, executionOptions, codeContext) + const terminal = this.terminals[0] + if (terminal) { + let command = commandContext.command + for (let i = 0; i < commandContext.args.length; i++) { + command += ` "${commandContext.args[i]}"` + } + terminal.run([command]) + return + } else { + console.log("No terminal found") + } + + if (atom.config.get("script.stopOnRerun")) { + this.stop() + } + this.emitter.emit("start") + if (!commandContext) { return } diff --git a/lib/script.js b/lib/script.js index 5bef9588..2b29ef29 100644 --- a/lib/script.js +++ b/lib/script.js @@ -1,6 +1,6 @@ "use babel" -import { CompositeDisposable } from "atom" +import { CompositeDisposable, Disposable } from "atom" import CodeContextBuilder from "./code-context-builder" import GrammarUtils from "./grammar-utils" @@ -69,6 +69,7 @@ let scriptOptions = null let scriptProfiles = [] let runtime = null const subscriptions = new CompositeDisposable() +let terminals = [] export function activate(state) { scriptView = new ScriptView(state.scriptViewState) @@ -91,7 +92,7 @@ export function activate(state) { const observer = new ViewRuntimeObserver(scriptView) - runtime = new Runtime(runner, codeContextBuilder, [observer]) + runtime = new Runtime(runner, codeContextBuilder, [observer], terminals) subscriptions.add( atom.commands.add("atom-workspace", { @@ -174,6 +175,7 @@ export function deactivate() { scriptOptionsView.close() scriptProfileRunView.close() subscriptions.dispose() + terminals.length = 0 GrammarUtils.deleteTempFiles() } @@ -220,7 +222,14 @@ export function provideBlankRuntime() { const runner = new Runner(new ScriptOptions()) const codeContextBuilder = new CodeContextBuilder() - return new Runtime(runner, codeContextBuilder, []) + return new Runtime(runner, codeContextBuilder, [], terminals) +} + +export function consumeTerminal(terminal) { + terminals.push(terminal) + return new Disposable(() => { + terminals = terminals.filter((t) => t !== terminal) + }) } export function serialize() { diff --git a/package.json b/package.json index 0d75164c..e075028f 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,38 @@ } } }, + "consumedServices": { + "runInTerminal": { + "description": "Allow to run commands in platformio-ide-terminal.", + "versions": { + "0.14.5": "consumeTerminal" + } + }, + "platformioIDETerminal": { + "description": "Allow to run commands in platformio-ide-terminal.", + "versions": { + "^1.1.0": "consumeTerminal" + } + }, + "terminusTerminal": { + "description": "Allow to run commands in terminus.", + "versions": { + "^1.1.1": "consumeTerminal" + } + }, + "terminationTerminal": { + "description": "Allow to run commands in termination.", + "versions": { + "^1.1.0": "consumeTerminal" + } + }, + "terminal": { + "description": "Allow to run commands in terminal.", + "versions": { + "^1.0.0": "consumeTerminal" + } + } + }, "keywords": [ "script", "runner",