Skip to content

Commit 0fad61d

Browse files
authored
fix: add model.runCommand (#22)
1 parent 62a083f commit 0fad61d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

spec/model-spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ describe('XTerminalModel', () => {
456456
expect(this.model.element.terminal.getSelection).toHaveBeenCalled()
457457
})
458458

459+
it('runCommand(cmd)', () => {
460+
this.model.element = this.element
461+
const expectedText = 'some text'
462+
this.model.runCommand(expectedText)
463+
expect(this.model.element.ptyProcess.write.calls.allArgs()).toEqual([[expectedText + (process.platform === 'win32' ? '\r' : '\n')]])
464+
})
465+
459466
it('pasteToTerminal(text)', () => {
460467
this.model.element = this.element
461468
const expectedText = 'some text'

src/model.js

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { XTerminalProfilesSingleton } from './profiles'
2323

2424
import fs from 'fs-extra'
2525
import path from 'path'
26+
import os from 'os'
2627

2728
import { URL } from 'whatwg-url'
2829

@@ -219,6 +220,10 @@ class XTerminalModel {
219220
return this.element.terminal.getSelection()
220221
}
221222

223+
runCommand (cmd) {
224+
this.pasteToTerminal(cmd + os.EOL.charAt(0))
225+
}
226+
222227
pasteToTerminal (text) {
223228
this.element.ptyProcess.write(text)
224229
}

src/x-terminal.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020

2121
import { CompositeDisposable } from 'atom'
22-
import os from 'os'
2322

2423
import { CONFIG_DATA } from './config'
2524
import { XTerminalElement } from './element'
@@ -282,7 +281,7 @@ class XTerminalSingleton {
282281
)
283282
await model.element.initializedPromise
284283
for (const command of commands) {
285-
model.pasteToTerminal(command + os.EOL)
284+
model.runCommand(command)
286285
}
287286
}
288287

0 commit comments

Comments
 (0)