Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can cooperate with Atom Terminals (allows inputs) #2337

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: CI
on:
- pull_request
- push
pull_request:
push:
branches:
- master

jobs:
Test:
Expand Down
25 changes: 19 additions & 6 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make sure that this has successfully run?

return
} else {
console.log("No terminal found")
}

if (atom.config.get("script.stopOnRerun")) {
this.stop()
}
this.emitter.emit("start")

if (!commandContext) {
return
}
Expand Down
15 changes: 12 additions & 3 deletions lib/script.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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", {
Expand Down Expand Up @@ -174,6 +175,7 @@ export function deactivate() {
scriptOptionsView.close()
scriptProfileRunView.close()
subscriptions.dispose()
terminals.length = 0
GrammarUtils.deleteTempFiles()
}

Expand Down Expand Up @@ -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() {
Expand Down
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allow almost any terminal including old ones that haven't been updated in a while. If we only want currently maintained terminals we can just consume terminal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt to support them if this doesn't break other things. Regarding package curation, I have some good plans which will solve many issues.

"description": "Allow to run commands in terminal.",
"versions": {
"^1.0.0": "consumeTerminal"
}
}
},
"keywords": [
"script",
"runner",
Expand Down