Skip to content

Commit 1ad29d3

Browse files
committed
consume terminal services
1 parent a079a49 commit 1ad29d3

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

lib/runtime.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export default class Runtime {
1010
// Public: Initializes a new {Runtime} instance
1111
//
1212
// This class is responsible for properly configuring {Runner}
13-
constructor(runner, codeContextBuilder, observers = []) {
13+
constructor(runner, codeContextBuilder, observers = [], terminals = []) {
1414
this.runner = runner;
1515
this.codeContextBuilder = codeContextBuilder;
1616
this.observers = observers;
17+
this.terminals = terminals;
1718
this.emitter = new Emitter();
1819
this.scriptOptions = this.runner.scriptOptions;
1920
_.each(this.observers, observer => observer.observe(this));
@@ -59,21 +60,16 @@ export default class Runtime {
5960
const executionOptions = !options ? this.scriptOptions : options;
6061
const commandContext = CommandContext.build(this, executionOptions, codeContext);
6162

62-
63-
// Will cooperate with Terminus to allow for inputs, if user has installed.
64-
try {
65-
var terminus = require('../../terminus/lib/terminus.js').provideTerminus();
66-
} catch (e) {
67-
var terminus = null;
68-
console.log('Could not find Terminus');
69-
}
70-
if (terminus != null) {
63+
const terminal = this.terminals[0];
64+
if (terminal) {
7165
let command = commandContext.command;
7266
for (let i = 0; i < commandContext.args.length; i++) {
7367
command += ` "${commandContext.args[i]}"`;
7468
}
75-
terminus.run([`printf "\\33c\\e[3J" && ${command}`]);
69+
terminal.run([`printf "\\33c\\e[3J" && ${command}`]);
7670
return;
71+
} else {
72+
console.log("No terminal found");
7773
}
7874

7975
if (atom.config.get('script.stopOnRerun')) this.stop();

lib/script.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use babel';
22

3-
import { CompositeDisposable } from 'atom';
3+
import { CompositeDisposable, Disposable } from 'atom';
44

55
import CodeContextBuilder from './code-context-builder';
66
import GrammarUtils from './grammar-utils';
@@ -63,6 +63,7 @@ export default {
6363
scriptProfileRunView: null,
6464
scriptOptions: null,
6565
scriptProfiles: [],
66+
terminals: [],
6667

6768
activate(state) {
6869
this.scriptView = new ScriptView(state.scriptViewState);
@@ -85,7 +86,7 @@ export default {
8586

8687
const observer = new ViewRuntimeObserver(this.scriptView);
8788

88-
this.runtime = new Runtime(runner, codeContextBuilder, [observer]);
89+
this.runtime = new Runtime(runner, codeContextBuilder, [observer], this.terminals);
8990

9091
this.subscriptions = new CompositeDisposable();
9192
this.subscriptions.add(atom.commands.add('atom-workspace', {
@@ -153,6 +154,7 @@ export default {
153154
this.scriptOptionsView.close();
154155
this.scriptProfileRunView.close();
155156
this.subscriptions.dispose();
157+
this.terminals.length = 0;
156158
GrammarUtils.deleteTempFiles();
157159
},
158160

@@ -161,6 +163,13 @@ export default {
161163
this.scriptView.removePanel();
162164
},
163165

166+
consumeTerminal(terminal) {
167+
this.terminals.push(terminal);
168+
return new Disposable(() => {
169+
this.terminals = this.terminals.filter((t) => t !== terminal);
170+
});
171+
},
172+
164173
// Public
165174
//
166175
// Service method that provides the default runtime that's configurable through Atom editor
@@ -199,7 +208,7 @@ export default {
199208
const runner = new Runner(new ScriptOptions());
200209
const codeContextBuilder = new CodeContextBuilder();
201210

202-
return new Runtime(runner, codeContextBuilder, []);
211+
return new Runtime(runner, codeContextBuilder, [], this.terminals);
203212
},
204213

205214
serialize() {

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,38 @@
5252
}
5353
}
5454
},
55+
"consumedServices": {
56+
"runInTerminal": {
57+
"description": "Allow to run commands in platformio-ide-terminal.",
58+
"versions": {
59+
"0.14.5": "consumeTerminal"
60+
}
61+
},
62+
"platformioIDETerminal": {
63+
"description": "Allow to run commands in platformio-ide-terminal.",
64+
"versions": {
65+
"^1.1.0": "consumeTerminal"
66+
}
67+
},
68+
"terminusTerminal": {
69+
"description": "Allow to run commands in terminus.",
70+
"versions": {
71+
"^1.1.1": "consumeTerminal"
72+
}
73+
},
74+
"terminationTerminal": {
75+
"description": "Allow to run commands in termination.",
76+
"versions": {
77+
"^1.1.0": "consumeTerminal"
78+
}
79+
},
80+
"terminal": {
81+
"description": "Allow to run commands in terminal.",
82+
"versions": {
83+
"^1.0.0": "consumeTerminal"
84+
}
85+
}
86+
},
5587
"scripts": {
5688
"lint": "eslint .",
5789
"lint:fix": "eslint . --fix",

0 commit comments

Comments
 (0)