Skip to content

Commit

Permalink
fix: add model.runCommand (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Mar 6, 2020
1 parent 62a083f commit 0fad61d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions spec/model-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ describe('XTerminalModel', () => {
expect(this.model.element.terminal.getSelection).toHaveBeenCalled()
})

it('runCommand(cmd)', () => {
this.model.element = this.element
const expectedText = 'some text'
this.model.runCommand(expectedText)
expect(this.model.element.ptyProcess.write.calls.allArgs()).toEqual([[expectedText + (process.platform === 'win32' ? '\r' : '\n')]])
})

it('pasteToTerminal(text)', () => {
this.model.element = this.element
const expectedText = 'some text'
Expand Down
5 changes: 5 additions & 0 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { XTerminalProfilesSingleton } from './profiles'

import fs from 'fs-extra'
import path from 'path'
import os from 'os'

import { URL } from 'whatwg-url'

Expand Down Expand Up @@ -219,6 +220,10 @@ class XTerminalModel {
return this.element.terminal.getSelection()
}

runCommand (cmd) {
this.pasteToTerminal(cmd + os.EOL.charAt(0))
}

pasteToTerminal (text) {
this.element.ptyProcess.write(text)
}
Expand Down
3 changes: 1 addition & 2 deletions src/x-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import { CompositeDisposable } from 'atom'
import os from 'os'

import { CONFIG_DATA } from './config'
import { XTerminalElement } from './element'
Expand Down Expand Up @@ -282,7 +281,7 @@ class XTerminalSingleton {
)
await model.element.initializedPromise
for (const command of commands) {
model.pasteToTerminal(command + os.EOL)
model.runCommand(command)
}
}

Expand Down

0 comments on commit 0fad61d

Please sign in to comment.