From 393703f2d171260b998223f465da015f51ce159d Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 19 Nov 2019 12:08:53 -0600 Subject: [PATCH 1/3] chore(eslint): use eslint standard --- .eslintrc.json | 27 ++++++++++++--------------- package.json | 5 +++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 54f53675..41c10a1d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,25 +1,22 @@ { "env": { + "browser": true, + "commonjs": true, "es6": true, "node": true, - "browser": true, - "jasmine": true, - "atomtest": true - }, - "parserOptions": { - "sourceType": "module", - "ecmaVersion": 8, - "ecmaFeatures": { - "impliedStrict": true - } + "jasmine": true }, + "extends": [ + "standard" + ], "globals": { - "atom": false + "Atomics": "readonly", + "SharedArrayBuffer": "readonly", + "atom": "readonly" + }, + "parserOptions": { + "ecmaVersion": 2018 }, - "extends": "eslint:recommended", "rules": { - "quotes": "warn", - "semi": "error", - "indent": ["error", 2, { "SwitchCase": 1 }] } } diff --git a/package.json b/package.json index 4188cc3b..ad878845 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,11 @@ "@semantic-release/apm-config": "^6.0.2", "atom-jasmine3-test-runner": "^4.3.9", "eslint": "^6.6.0", + "eslint-config-standard": "^14.1.0", + "eslint-plugin-import": "^2.18.2", + "eslint-plugin-node": "^10.0.0", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-standard": "^4.0.1", "husky": "3.1.0", "semantic-release": "^15.13.31" }, From 5bcbc286db01dcdf3cb65eb82d3f101383b187da Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 19 Nov 2019 12:17:16 -0600 Subject: [PATCH 2/3] chore(lint): lint with new standard --- lib/dialog.js | 56 +-- lib/input-dialog.js | 32 +- lib/process.js | 86 ++-- lib/rename-dialog.js | 20 +- lib/status-bar.js | 792 +++++++++++++++++----------------- lib/status-icon.js | 133 +++--- lib/terminus.js | 502 +++++++++++----------- lib/view.js | 963 +++++++++++++++++++++--------------------- spec/runner.js | 6 +- spec/terminus-spec.js | 38 +- 10 files changed, 1318 insertions(+), 1310 deletions(-) diff --git a/lib/dialog.js b/lib/dialog.js index 09dc9a1d..44480f12 100644 --- a/lib/dialog.js +++ b/lib/dialog.js @@ -1,50 +1,50 @@ -const { TextEditorView, View } = require("atom-space-pen-views"); +const { TextEditorView, View } = require('atom-space-pen-views') class Dialog extends View { - static content({prompt} = {}) { - this.div({class: "terminus-dialog"}, () => { - this.label(prompt, {class: "icon", outlet: "promptText"}); - this.subview("miniEditor", new TextEditorView({mini: true})); - this.label("Escape (Esc) to exit", {style: "width: 50%;"}); - this.label("Enter (\u21B5) to confirm", {style: "width: 50%; text-align: right;"}); - }); + static content ({ prompt } = {}) { + this.div({ class: 'terminus-dialog' }, () => { + this.label(prompt, { class: 'icon', outlet: 'promptText' }) + this.subview('miniEditor', new TextEditorView({ mini: true })) + this.label('Escape (Esc) to exit', { style: 'width: 50%;' }) + this.label('Enter (\u21B5) to confirm', { style: 'width: 50%; text-align: right;' }) + }) } - initialize({iconClass, placeholderText, stayOpen} = {}) { - if (iconClass) { this.promptText.addClass(iconClass); } + initialize ({ iconClass, placeholderText, stayOpen } = {}) { + if (iconClass) { this.promptText.addClass(iconClass) } atom.commands.add(this.element, { - "core:confirm": () => this.onConfirm(this.miniEditor.getText()), - "core:cancel": () => this.cancel() - }); + 'core:confirm': () => this.onConfirm(this.miniEditor.getText()), + 'core:cancel': () => this.cancel() + }) if (!stayOpen) { - this.miniEditor.on("blur", () => this.close()); + this.miniEditor.on('blur', () => this.close()) } if (placeholderText) { - this.miniEditor.getModel().setText(placeholderText); - this.miniEditor.getModel().selectAll(); + this.miniEditor.getModel().setText(placeholderText) + this.miniEditor.getModel().selectAll() } } - attach() { - this.panel = atom.workspace.addModalPanel({item: this.element}); - this.miniEditor.focus(); - this.miniEditor.getModel().scrollToCursorPosition(); + attach () { + this.panel = atom.workspace.addModalPanel({ item: this.element }) + this.miniEditor.focus() + this.miniEditor.getModel().scrollToCursorPosition() } - close() { - const panelToDestroy = this.panel; - this.panel = null; + close () { + const panelToDestroy = this.panel + this.panel = null if (panelToDestroy) { - panelToDestroy.destroy(); + panelToDestroy.destroy() } - atom.workspace.getActivePane().activate(); + atom.workspace.getActivePane().activate() } - cancel() { - this.close(); + cancel () { + this.close() } } -module.exports = Dialog; +module.exports = Dialog diff --git a/lib/input-dialog.js b/lib/input-dialog.js index f8dd5a0d..11f63fb0 100644 --- a/lib/input-dialog.js +++ b/lib/input-dialog.js @@ -1,29 +1,29 @@ -const Dialog = require("./dialog"); -const os = require("os"); +const Dialog = require('./dialog') +const os = require('os') class InputDialog extends Dialog { - constructor(terminalView) { + constructor (terminalView) { super({ - prompt: "Insert Text", - iconClass: "icon-keyboard", + prompt: 'Insert Text', + iconClass: 'icon-keyboard', stayOpen: true - }); + }) - this.terminalView = terminalView; + this.terminalView = terminalView } - onConfirm(input) { - let eol; - if (atom.config.get("terminus.toggles.runInsertedText")) { - eol = os.EOL; + onConfirm (input) { + let eol + if (atom.config.get('terminus.toggles.runInsertedText')) { + eol = os.EOL } else { - eol = ""; + eol = '' } - const data = `${input}${eol}`; - this.terminalView.input(data); - this.cancel(); + const data = `${input}${eol}` + this.terminalView.input(data) + this.cancel() } } -module.exports = InputDialog; +module.exports = InputDialog diff --git a/lib/process.js b/lib/process.js index 7a432d26..7e60d899 100644 --- a/lib/process.js +++ b/lib/process.js @@ -1,69 +1,69 @@ -const pty = require("node-pty-prebuilt-multiarch"); -const _ = require("underscore"); -const child = require("child_process"); +const pty = require('node-pty-prebuilt-multiarch') +const _ = require('underscore') +const child = require('child_process') -function getSystemLanguage() { - let language = "en_US.UTF-8"; - if (process.platform === "darwin") { +function getSystemLanguage () { + let language = 'en_US.UTF-8' + if (process.platform === 'darwin') { try { - const command = "plutil -convert json -o - ~/Library/Preferences/.GlobalPreferences.plist"; - language = `${JSON.parse(child.execSync(command).toString()).AppleLocale}.UTF-8`; + const command = 'plutil -convert json -o - ~/Library/Preferences/.GlobalPreferences.plist' + language = `${JSON.parse(child.execSync(command).toString()).AppleLocale}.UTF-8` } catch (error) { // do nothing } } - return language; + return language } -const systemLanguage = getSystemLanguage(); +const systemLanguage = getSystemLanguage() -function getFilteredEnvironment() { - const env = _.omit(process.env, "ATOM_HOME", "ELECTRON_RUN_AS_NODE", "GOOGLE_API_KEY", "NODE_ENV", "NODE_PATH", "userAgent", "taskPath"); - if (!env.LANG) { env.LANG = systemLanguage; } - env.TERM_PROGRAM = "terminus"; - return env; +function getFilteredEnvironment () { + const env = _.omit(process.env, 'ATOM_HOME', 'ELECTRON_RUN_AS_NODE', 'GOOGLE_API_KEY', 'NODE_ENV', 'NODE_PATH', 'userAgent', 'taskPath') + if (!env.LANG) { env.LANG = systemLanguage } + env.TERM_PROGRAM = 'terminus' + return env } -const filteredEnvironment = getFilteredEnvironment(); +const filteredEnvironment = getFilteredEnvironment() -module.exports = function(pwd, shell, args, env) { - let ptyProcess; - const callback = this.async(); +module.exports = function (pwd, shell, args, env) { + let ptyProcess + const callback = this.async() if (shell) { ptyProcess = pty.fork(shell, args, { cwd: pwd, env: _.extend(filteredEnvironment, env), - name: "xterm-256color" - }); + name: 'xterm-256color' + }) } else { - ptyProcess = pty.open(); + ptyProcess = pty.open() } - const emitTitle = _.throttle(() => global.emit("terminus:title", ptyProcess.process), 500, true); + const emitTitle = _.throttle(() => global.emit('terminus:title', ptyProcess.process), 500, true) - ptyProcess.on("data", function(data) { - global.emit("terminus:data", data); - emitTitle(); - }); + ptyProcess.on('data', function (data) { + global.emit('terminus:data', data) + emitTitle() + }) - ptyProcess.on("exit", function() { - global.emit("terminus:exit"); - callback(); - }); + ptyProcess.on('exit', function () { + global.emit('terminus:exit') + callback() + }) - return process.on("message", function({event, cols, rows, text}={}) { + return process.on('message', function ({ event, cols, rows, text } = {}) { switch (event) { - case "resize": { - ptyProcess.resize(cols, rows); - break; + case 'resize': { + ptyProcess.resize(cols, rows) + break } - case "input": { - ptyProcess.write(text); - break; + case 'input': { + ptyProcess.write(text) + break } - case "pty": { - global.emit("terminus:pty", ptyProcess.pty); - break; + case 'pty': { + global.emit('terminus:pty', ptyProcess.pty) + break } } - }); -}; + }) +} diff --git a/lib/rename-dialog.js b/lib/rename-dialog.js index 47b0dedd..98eee1c5 100644 --- a/lib/rename-dialog.js +++ b/lib/rename-dialog.js @@ -1,20 +1,20 @@ -const Dialog = require("./dialog"); +const Dialog = require('./dialog') class RenameDialog extends Dialog { - constructor(statusIcon) { + constructor (statusIcon) { super({ - prompt: "Rename", - iconClass: "icon-pencil", + prompt: 'Rename', + iconClass: 'icon-pencil', placeholderText: statusIcon.getName() - }); + }) - this.statusIcon = statusIcon; + this.statusIcon = statusIcon } - onConfirm(newTitle) { - this.statusIcon.updateName(newTitle.trim()); - this.cancel(); + onConfirm (newTitle) { + this.statusIcon.updateName(newTitle.trim()) + this.cancel() } } -module.exports = RenameDialog; +module.exports = RenameDialog diff --git a/lib/status-bar.js b/lib/status-bar.js index 0076342a..8f6fbb82 100644 --- a/lib/status-bar.js +++ b/lib/status-bar.js @@ -1,610 +1,614 @@ -const {CompositeDisposable} = require("atom"); -const {$, View} = require("atom-space-pen-views"); +const { CompositeDisposable } = require('atom') +const { $, View } = require('atom-space-pen-views') -const TerminusView = require("./view"); -const StatusIcon = require("./status-icon"); +const TerminusView = require('./view') +const StatusIcon = require('./status-icon') -const path = require("path"); -const _ = require("underscore"); +const path = require('path') +const _ = require('underscore') class StatusBar extends View { - static content() { - this.div({class: "terminus status-bar", tabindex: -1}, () => { - this.i({class: "icon icon-plus", click: "newTerminalView", outlet: "plusBtn"}); - this.ul({class: "list-inline status-container", tabindex: "-1", outlet: "statusContainer", is: "space-pen-ul"}); - this.i({class: "icon icon-x", click: "closeAll", outlet: "closeBtn"}); - }); - } - - initialize(statusBarProvider) { - this.statusBarProvider = statusBarProvider; - this.subscriptions = new CompositeDisposable(); - - this.onDropTabBar = this.onDropTabBar.bind(this); - this.onDragStart = this.onDragStart.bind(this); - this.onDragEnd = this.onDragEnd.bind(this); - this.onDragLeave = this.onDragLeave.bind(this); - this.onDragOver = this.onDragOver.bind(this); - this.onDrop = this.onDrop.bind(this); - - this.subscriptions.add(atom.commands.add("atom-workspace", { - "terminus:focus": () => this.focusTerminal(), - "terminus:new": () => this.newTerminalView(), - "terminus:toggle": () => this.toggle(), - "terminus:next": () => { - if (!this.activeTerminal) { return; } - if (this.activeTerminal.isAnimating()) { return; } - if (this.activeNextTerminalView()) { return this.activeTerminal.open(); } + static content () { + this.div({ class: 'terminus status-bar', tabindex: -1 }, () => { + this.i({ class: 'icon icon-plus', click: 'newTerminalView', outlet: 'plusBtn' }) + this.ul({ class: 'list-inline status-container', tabindex: '-1', outlet: 'statusContainer', is: 'space-pen-ul' }) + this.i({ class: 'icon icon-x', click: 'closeAll', outlet: 'closeBtn' }) + }) + } + + initialize (statusBarProvider) { + this.statusBarProvider = statusBarProvider + this.subscriptions = new CompositeDisposable() + + this.onDropTabBar = this.onDropTabBar.bind(this) + this.onDragStart = this.onDragStart.bind(this) + this.onDragEnd = this.onDragEnd.bind(this) + this.onDragLeave = this.onDragLeave.bind(this) + this.onDragOver = this.onDragOver.bind(this) + this.onDrop = this.onDrop.bind(this) + + this.subscriptions.add(atom.commands.add('atom-workspace', { + 'terminus:focus': () => this.focusTerminal(), + 'terminus:new': () => this.newTerminalView(), + 'terminus:toggle': () => this.toggle(), + 'terminus:next': () => { + if (!this.activeTerminal) { return } + if (this.activeTerminal.isAnimating()) { return } + if (this.activeNextTerminalView()) { return this.activeTerminal.open() } }, - "terminus:prev": () => { - if (!this.activeTerminal) { return; } - if (this.activeTerminal.isAnimating()) { return; } - if (this.activePrevTerminalView()) { return this.activeTerminal.open(); } + 'terminus:prev': () => { + if (!this.activeTerminal) { return } + if (this.activeTerminal.isAnimating()) { return } + if (this.activePrevTerminalView()) { return this.activeTerminal.open() } }, - "terminus:clear": () => this.clear(), - "terminus:close": () => this.destroyActiveTerm(), - "terminus:close-all": () => this.closeAll(), - "terminus:rename": () => this.runInActiveView(i => i.rename()), - "terminus:insert-selected-text": () => this.runInActiveView(i => i.insertSelection("$S")), - "terminus:insert-text": () => this.runInActiveView(i => i.inputDialog()), - "terminus:insert-custom-text-1": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText1"))), - "terminus:insert-custom-text-2": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText2"))), - "terminus:insert-custom-text-3": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText3"))), - "terminus:insert-custom-text-4": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText4"))), - "terminus:insert-custom-text-5": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText5"))), - "terminus:insert-custom-text-6": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText6"))), - "terminus:insert-custom-text-7": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText7"))), - "terminus:insert-custom-text-8": () => this.runInActiveView(i => i.insertSelection(atom.config.get("terminus.customTexts.customText8"))), - "terminus:fullscreen": () => this.activeTerminal.maximize() - })); - - this.subscriptions.add(atom.commands.add(".xterm", { - "terminus:paste": () => this.runInActiveView(i => i.paste()), - "terminus:copy": () => this.runInActiveView(i => i.copy()) - })); + 'terminus:clear': () => this.clear(), + 'terminus:close': () => this.destroyActiveTerm(), + 'terminus:close-all': () => this.closeAll(), + 'terminus:rename': () => this.runInActiveView(i => i.rename()), + 'terminus:insert-selected-text': () => this.runInActiveView(i => i.insertSelection('$S')), + 'terminus:insert-text': () => this.runInActiveView(i => i.inputDialog()), + 'terminus:insert-custom-text-1': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText1'))), + 'terminus:insert-custom-text-2': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText2'))), + 'terminus:insert-custom-text-3': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText3'))), + 'terminus:insert-custom-text-4': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText4'))), + 'terminus:insert-custom-text-5': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText5'))), + 'terminus:insert-custom-text-6': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText6'))), + 'terminus:insert-custom-text-7': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText7'))), + 'terminus:insert-custom-text-8': () => this.runInActiveView(i => i.insertSelection(atom.config.get('terminus.customTexts.customText8'))), + 'terminus:fullscreen': () => this.activeTerminal.maximize() + })) + + this.subscriptions.add(atom.commands.add('.xterm', { + 'terminus:paste': () => this.runInActiveView(i => i.paste()), + 'terminus:copy': () => this.runInActiveView(i => i.copy()) + })) this.subscriptions.add(atom.workspace.onDidChangeActivePaneItem(item => { - if (!item) { return; } + if (!item) { return } - if (item.constructor.name === "TerminusView") { - setTimeout(item.focus, 100); - } else if (item.constructor.name === "TextEditor") { - const mapping = atom.config.get("terminus.core.mapTerminalsTo"); - if (mapping === "None") { return; } - if (!item.getPath()) { return; } + if (item.constructor.name === 'TerminusView') { + setTimeout(item.focus, 100) + } else if (item.constructor.name === 'TextEditor') { + const mapping = atom.config.get('terminus.core.mapTerminalsTo') + if (mapping === 'None') { return } + if (!item.getPath()) { return } - let nextTerminal; + let nextTerminal switch (mapping) { - case "File": - nextTerminal = this.getTerminalById(item.getPath(), view => view.getId().filePath); - break; - case "Folder": - nextTerminal = this.getTerminalById(path.dirname(item.getPath()), view => view.getId().folderPath); - break; + case 'File': + nextTerminal = this.getTerminalById(item.getPath(), view => view.getId().filePath) + break + case 'Folder': + nextTerminal = this.getTerminalById(path.dirname(item.getPath()), view => view.getId().folderPath) + break } - const prevTerminal = this.getActiveTerminalView(); + const prevTerminal = this.getActiveTerminalView() if (prevTerminal !== nextTerminal) { if (!nextTerminal) { - if (atom.config.get("terminus.core.mapTerminalsToAutoOpen")) { - nextTerminal = this.createTerminalView(); + if (atom.config.get('terminus.core.mapTerminalsToAutoOpen')) { + nextTerminal = this.createTerminalView() } } else { - this.setActiveTerminalView(nextTerminal); - if (prevTerminal && prevTerminal.panel.isVisible()) { - nextTerminal.toggle(); + this.setActiveTerminalView(nextTerminal) + if (prevTerminal && prevTerminal.panel.isVisible()) { + nextTerminal.toggle() } } } } - })); + })) - this.registerContextMenu(); + this.registerContextMenu() - this.subscriptions.add(atom.tooltips.add(this.plusBtn, {title: "New Terminal"})); - this.subscriptions.add(atom.tooltips.add(this.closeBtn, {title: "Close All"})); + this.subscriptions.add(atom.tooltips.add(this.plusBtn, { title: 'New Terminal' })) + this.subscriptions.add(atom.tooltips.add(this.closeBtn, { title: 'Close All' })) - this.statusContainer.on("dblclick", event => { - if (event.target === event.delegateTarget) { this.newTerminalView(); } - }); + this.statusContainer.on('dblclick', event => { + if (event.target === event.delegateTarget) { this.newTerminalView() } + }) - this.statusContainer.on("dragstart", ".terminus-status-icon", this.onDragStart); - this.statusContainer.on("dragend", ".terminus-status-icon", this.onDragEnd); - this.statusContainer.on("dragleave", this.onDragLeave); - this.statusContainer.on("dragover", this.onDragOver); - this.statusContainer.on("drop", this.onDrop); + this.statusContainer.on('dragstart', '.terminus-status-icon', this.onDragStart) + this.statusContainer.on('dragend', '.terminus-status-icon', this.onDragEnd) + this.statusContainer.on('dragleave', this.onDragLeave) + this.statusContainer.on('dragover', this.onDragOver) + this.statusContainer.on('drop', this.onDrop) const handleBlur = () => { - const terminal = TerminusView.getFocusedTerminal(); + const terminal = TerminusView.getFocusedTerminal() if (terminal) { - this.returnFocus = this.terminalViewForTerminal(terminal); - terminal.blur(); + this.returnFocus = this.terminalViewForTerminal(terminal) + terminal.blur() } - }; + } const handleFocus = () => { if (this.returnFocus) { setTimeout(() => { if (this.returnFocus) { - this.returnFocus.focus(true); + this.returnFocus.focus(true) } - this.returnFocus = null; - }, 100); + this.returnFocus = null + }, 100) + } + } + + window.addEventListener('blur', handleBlur) + this.subscriptions.add({ + dispose () { + window.removeEventListener('blur', handleBlur) + } + }) + + window.addEventListener('focus', handleFocus) + this.subscriptions.add({ + dispose () { + window.removeEventListener('focus', handleFocus) } - }; - - window.addEventListener("blur", handleBlur); - this.subscriptions.add({dispose() { - window.removeEventListener("blur", handleBlur); - }}); - - window.addEventListener("focus", handleFocus); - this.subscriptions.add({dispose() { - window.removeEventListener("focus", handleFocus); - }}); - - this.attach(); - } - - registerContextMenu() { - this.subscriptions.add(atom.commands.add(".terminus.status-bar", { - "terminus:status-red": this.setStatusColor, - "terminus:status-orange": this.setStatusColor, - "terminus:status-yellow": this.setStatusColor, - "terminus:status-green": this.setStatusColor, - "terminus:status-blue": this.setStatusColor, - "terminus:status-purple": this.setStatusColor, - "terminus:status-pink": this.setStatusColor, - "terminus:status-cyan": this.setStatusColor, - "terminus:status-magenta": this.setStatusColor, - "terminus:status-default": this.clearStatusColor, - "terminus:context-close"(event) { - $(event.target).closest(".terminus-status-icon")[0].terminalView.destroy(); + }) + + this.attach() + } + + registerContextMenu () { + this.subscriptions.add(atom.commands.add('.terminus.status-bar', { + 'terminus:status-red': this.setStatusColor, + 'terminus:status-orange': this.setStatusColor, + 'terminus:status-yellow': this.setStatusColor, + 'terminus:status-green': this.setStatusColor, + 'terminus:status-blue': this.setStatusColor, + 'terminus:status-purple': this.setStatusColor, + 'terminus:status-pink': this.setStatusColor, + 'terminus:status-cyan': this.setStatusColor, + 'terminus:status-magenta': this.setStatusColor, + 'terminus:status-default': this.clearStatusColor, + 'terminus:context-close' (event) { + $(event.target).closest('.terminus-status-icon')[0].terminalView.destroy() }, - "terminus:context-hide"(event) { - const statusIcon = $(event.target).closest(".terminus-status-icon")[0]; - if (statusIcon.isActive()) { statusIcon.terminalView.hide(); } + 'terminus:context-hide' (event) { + const statusIcon = $(event.target).closest('.terminus-status-icon')[0] + if (statusIcon.isActive()) { statusIcon.terminalView.hide() } }, - "terminus:context-rename"(event) { - $(event.target).closest(".terminus-status-icon")[0].rename(); + 'terminus:context-rename' (event) { + $(event.target).closest('.terminus-status-icon')[0].rename() } - })); + })) } - registerPaneSubscription() { + registerPaneSubscription () { this.subscriptions.add(this.paneSubscription = atom.workspace.observePanes(pane => { - const paneElement = $(atom.views.getView(pane)); - const tabBar = paneElement.find("ul"); - - tabBar.on("drop", event => this.onDropTabBar(event, pane)); - tabBar.on("dragstart", event => { - if ((event.target.item ? event.target.item.constructor.name : undefined) !== "TerminusView") { return; } - event.originalEvent.dataTransfer.setData("terminus-tab", "true"); - }); - pane.onDidDestroy(() => tabBar.off("drop", this.onDropTabBar)); - })); - } - - createTerminalView(autoRun) { - const shell = atom.config.get("terminus.core.shell"); - const shellArguments = atom.config.get("terminus.core.shellArguments"); - const args = shellArguments.split(/\s+/g).filter(arg => arg); - const shellEnv = atom.config.get("terminus.core.shellEnv"); - let env = {}; - shellEnv.split(" ").forEach(element => { - const configVar = element.split("="); - const envVar = {}; - envVar[configVar[0]] = configVar[1]; - env = _.extend(env, envVar); - }); - return this.createEmptyTerminalView(autoRun, shell, args, env); - } - - createEmptyTerminalView(autoRun=[], shell = null, args = [], env= {}) { - if (!this.paneSubscription) { this.registerPaneSubscription(); } - - let projectFolder = atom.project.getPaths()[0]; - const editor = atom.workspace.getActiveTextEditor(); - const editorPath = editor && editor.getPath(); - - let editorFolder; + const paneElement = $(atom.views.getView(pane)) + const tabBar = paneElement.find('ul') + + tabBar.on('drop', event => this.onDropTabBar(event, pane)) + tabBar.on('dragstart', event => { + if ((event.target.item ? event.target.item.constructor.name : undefined) !== 'TerminusView') { return } + event.originalEvent.dataTransfer.setData('terminus-tab', 'true') + }) + pane.onDidDestroy(() => tabBar.off('drop', this.onDropTabBar)) + })) + } + + createTerminalView (autoRun) { + const shell = atom.config.get('terminus.core.shell') + const shellArguments = atom.config.get('terminus.core.shellArguments') + const args = shellArguments.split(/\s+/g).filter(arg => arg) + const shellEnv = atom.config.get('terminus.core.shellEnv') + let env = {} + shellEnv.split(' ').forEach(element => { + const configVar = element.split('=') + const envVar = {} + envVar[configVar[0]] = configVar[1] + env = _.extend(env, envVar) + }) + return this.createEmptyTerminalView(autoRun, shell, args, env) + } + + createEmptyTerminalView (autoRun = [], shell = null, args = [], env = {}) { + if (!this.paneSubscription) { this.registerPaneSubscription() } + + let projectFolder = atom.project.getPaths()[0] + const editor = atom.workspace.getActiveTextEditor() + const editorPath = editor && editor.getPath() + + let editorFolder if (editorPath) { - editorFolder = path.dirname(editorPath); + editorFolder = path.dirname(editorPath) for (const directory of atom.project.getPaths()) { if (editorPath.indexOf(directory) >= 0) { - projectFolder = directory; + projectFolder = directory } } } - if (!projectFolder || projectFolder.includes("atom://")) { projectFolder = undefined; } + if (!projectFolder || projectFolder.includes('atom://')) { projectFolder = undefined } - const home = process.platform === "win32" ? process.env.HOMEPATH : process.env.HOME; + const home = process.platform === 'win32' ? process.env.HOMEPATH : process.env.HOME - let pwd; - switch (atom.config.get("terminus.core.workingDirectory")) { - case "Project": pwd = (projectFolder || editorFolder || home); break; - case "Active File": pwd = (editorFolder || projectFolder || home); break; - default: pwd = home; + let pwd + switch (atom.config.get('terminus.core.workingDirectory')) { + case 'Project': pwd = (projectFolder || editorFolder || home); break + case 'Active File': pwd = (editorFolder || projectFolder || home); break + default: pwd = home } - let id = (editorPath || projectFolder || home); - id = {filePath: id, folderPath: path.dirname(id)}; + let id = (editorPath || projectFolder || home) + id = { filePath: id, folderPath: path.dirname(id) } - const statusIcon = new StatusIcon(); - const terminusView = new TerminusView(id, pwd, statusIcon, this, shell, args, env, autoRun); - statusIcon.initialize(terminusView); + const statusIcon = new StatusIcon() + const terminusView = new TerminusView(id, pwd, statusIcon, this, shell, args, env, autoRun) + statusIcon.initialize(terminusView) - terminusView.attach(); + terminusView.attach() - this.terminalViews.push(terminusView); - this.statusContainer.append(statusIcon); - return terminusView; + this.terminalViews.push(terminusView) + this.statusContainer.append(statusIcon) + return terminusView } - activeNextTerminalView() { - const index = this.indexOf(this.activeTerminal); - if (index < 0) { return false; } - return this.activeTerminalView(index + 1); + activeNextTerminalView () { + const index = this.indexOf(this.activeTerminal) + if (index < 0) { return false } + return this.activeTerminalView(index + 1) } - activePrevTerminalView() { - const index = this.indexOf(this.activeTerminal); - if (index < 0) { return false; } - return this.activeTerminalView(index - 1); + activePrevTerminalView () { + const index = this.indexOf(this.activeTerminal) + if (index < 0) { return false } + return this.activeTerminalView(index - 1) } - indexOf(view) { - return this.terminalViews.indexOf(view); + indexOf (view) { + return this.terminalViews.indexOf(view) } - activeTerminalView(index) { - if (this.terminalViews.length < 2) { return false; } + activeTerminalView (index) { + if (this.terminalViews.length < 2) { return false } if (index >= this.terminalViews.length) { - index = 0; + index = 0 } if (index < 0) { - index = this.terminalViews.length - 1; + index = this.terminalViews.length - 1 } - this.activeTerminal = this.terminalViews[index]; - return true; + this.activeTerminal = this.terminalViews[index] + return true } - getActiveTerminalView() { - return this.activeTerminal; + getActiveTerminalView () { + return this.activeTerminal } - focusTerminal() { - if (!this.activeTerminal) { return; } + focusTerminal () { + if (!this.activeTerminal) { return } if (TerminusView.getFocusedTerminal()) { - this.activeTerminal.blur(); + this.activeTerminal.blur() } else { - this.activeTerminal.focusTerminal(); + this.activeTerminal.focusTerminal() } } - getTerminalById(target, selector) { - if (!selector) { selector = terminal => terminal.id; } + getTerminalById (target, selector) { + if (!selector) { selector = terminal => terminal.id } for (const terminal of this.terminalViews) { if (terminal) { - if (selector(terminal) === target) { return terminal; } + if (selector(terminal) === target) { return terminal } } } - return null; + return null } - terminalViewForTerminal(terminal) { + terminalViewForTerminal (terminal) { for (const terminalView of this.terminalViews) { if (terminalView) { - if (terminalView.getTerminal() === terminal) { return terminalView; } + if (terminalView.getTerminal() === terminal) { return terminalView } } } - return null; + return null } - runInActiveView(callback) { - const view = this.getActiveTerminalView(); + runInActiveView (callback) { + const view = this.getActiveTerminalView() if (view) { - return callback(view); + return callback(view) } - return null; + return null } - runNewTerminal() { - this.activeTerminal = this.createEmptyTerminalView(); - this.activeTerminal.toggle(); - return this.activeTerminal; + runNewTerminal () { + this.activeTerminal = this.createEmptyTerminalView() + this.activeTerminal.toggle() + return this.activeTerminal } - runCommandInNewTerminal(commands) { - this.activeTerminal = this.createTerminalView(commands); - this.activeTerminal.toggle(); - return this.activeTerminal; + runCommandInNewTerminal (commands) { + this.activeTerminal = this.createTerminalView(commands) + this.activeTerminal.toggle() + return this.activeTerminal } - runInOpenView(callback) { - const view = this.getActiveTerminalView(); + runInOpenView (callback) { + const view = this.getActiveTerminalView() if (view && view.panel.isVisible()) { - return callback(view); + return callback(view) } - return null; + return null } - setActiveTerminalView(view) { - this.activeTerminal = view; + setActiveTerminalView (view) { + this.activeTerminal = view } - removeTerminalView(view) { - const index = this.indexOf(view); - if (index < 0) { return; } - this.terminalViews.splice(index, 1); + removeTerminalView (view) { + const index = this.indexOf(view) + if (index < 0) { return } + this.terminalViews.splice(index, 1) - this.activateAdjacentTerminal(index); + this.activateAdjacentTerminal(index) } - activateAdjacentTerminal(index = 0) { - if (this.terminalViews.length === 0) { return false; } + activateAdjacentTerminal (index = 0) { + if (this.terminalViews.length === 0) { return false } - index = Math.max(0, index - 1); - this.activeTerminal = this.terminalViews[index]; + index = Math.max(0, index - 1) + this.activeTerminal = this.terminalViews[index] - return true; + return true } - newTerminalView() { - if (this.activeTerminal && this.activeTerminal.animating) { return; } + newTerminalView () { + if (this.activeTerminal && this.activeTerminal.animating) { return } - this.activeTerminal = this.createTerminalView(); - this.activeTerminal.toggle(); + this.activeTerminal = this.createTerminalView() + this.activeTerminal.toggle() } - attach() { - this.statusBarProvider.addLeftTile({item: this, priority: -93}); + attach () { + this.statusBarProvider.addLeftTile({ item: this, priority: -93 }) } - destroyActiveTerm() { - if (!this.activeTerminal) { return; } + destroyActiveTerm () { + if (!this.activeTerminal) { return } - const index = this.indexOf(this.activeTerminal); - this.activeTerminal.destroy(); - this.activeTerminal = null; + const index = this.indexOf(this.activeTerminal) + this.activeTerminal.destroy() + this.activeTerminal = null - this.activateAdjacentTerminal(index); + this.activateAdjacentTerminal(index) } - closeAll() { + closeAll () { for (let i = this.terminalViews.length - 1; i >= 0; i--) { - const view = this.terminalViews[i]; + const view = this.terminalViews[i] if (view) { - view.destroy(); + view.destroy() } } - this.activeTerminal = null; + this.activeTerminal = null } - destroy() { - this.subscriptions.dispose(); + destroy () { + this.subscriptions.dispose() for (let i = this.terminalViews.length - 1; i >= 0; i--) { - const view = this.terminalViews[i]; + const view = this.terminalViews[i] if (view) { - view.ptyProcess.terminate(); - view.terminal.destroy(); + view.ptyProcess.terminate() + view.terminal.destroy() } } - this.detach(); + this.detach() } - toggle() { + toggle () { if (this.terminalViews.length === 0) { - this.activeTerminal = this.createTerminalView(); + this.activeTerminal = this.createTerminalView() } else if (this.activeTerminal === null) { - this.activeTerminal = this.terminalViews[0]; + this.activeTerminal = this.terminalViews[0] } - this.activeTerminal.toggle(); + this.activeTerminal.toggle() } - clear() { - this.destroyActiveTerm(); - this.newTerminalView(); + clear () { + this.destroyActiveTerm() + this.newTerminalView() } - setStatusColor(event) { - let color = event.type.match(/\w+$/)[0]; - color = atom.config.get(`terminus.iconColors.${color}`).toRGBAString(); - $(event.target).closest(".terminus-status-icon").css("color", color); + setStatusColor (event) { + let color = event.type.match(/\w+$/)[0] + color = atom.config.get(`terminus.iconColors.${color}`).toRGBAString() + $(event.target).closest('.terminus-status-icon').css('color', color) } - clearStatusColor(event) { - $(event.target).closest(".terminus-status-icon").css("color", ""); + clearStatusColor (event) { + $(event.target).closest('.terminus-status-icon').css('color', '') } - onDragStart(event) { - event.originalEvent.dataTransfer.setData("terminus-panel", "true"); + onDragStart (event) { + event.originalEvent.dataTransfer.setData('terminus-panel', 'true') - const element = $(event.target).closest(".terminus-status-icon"); - element.addClass("is-dragging"); - event.originalEvent.dataTransfer.setData("from-index", element.index()); + const element = $(event.target).closest('.terminus-status-icon') + element.addClass('is-dragging') + event.originalEvent.dataTransfer.setData('from-index', element.index()) } - onDragLeave() { - this.removePlaceholder(); + onDragLeave () { + this.removePlaceholder() } - onDragEnd() { - this.clearDropTarget(); + onDragEnd () { + this.clearDropTarget() } - onDragOver(event) { - event.preventDefault(); - event.stopPropagation(); - if (event.originalEvent.dataTransfer.getData("terminus") !== "true") { - return; + onDragOver (event) { + event.preventDefault() + event.stopPropagation() + if (event.originalEvent.dataTransfer.getData('terminus') !== 'true') { + return } - const newDropTargetIndex = this.getDropTargetIndex(event); - if (!newDropTargetIndex) { return; } - this.removeDropTargetClasses(); - const statusIcons = this.statusContainer.children(".terminus-status-icon"); + const newDropTargetIndex = this.getDropTargetIndex(event) + if (!newDropTargetIndex) { return } + this.removeDropTargetClasses() + const statusIcons = this.statusContainer.children('.terminus-status-icon') if (newDropTargetIndex < statusIcons.length) { - const element = statusIcons.eq(newDropTargetIndex).addClass("is-drop-target"); - this.getPlaceholder().insertBefore(element); + const element = statusIcons.eq(newDropTargetIndex).addClass('is-drop-target') + this.getPlaceholder().insertBefore(element) } else { - const element = statusIcons.eq(newDropTargetIndex - 1).addClass("drop-target-is-after"); - this.getPlaceholder().insertAfter(element); + const element = statusIcons.eq(newDropTargetIndex - 1).addClass('drop-target-is-after') + this.getPlaceholder().insertAfter(element) } } - onDrop(event) { - const {dataTransfer} = event.originalEvent; - const panelEvent = dataTransfer.getData("terminus-panel") === "true"; - const tabEvent = dataTransfer.getData("terminus-tab") === "true"; - if (!panelEvent && !tabEvent) { return; } + onDrop (event) { + const { dataTransfer } = event.originalEvent + const panelEvent = dataTransfer.getData('terminus-panel') === 'true' + const tabEvent = dataTransfer.getData('terminus-tab') === 'true' + if (!panelEvent && !tabEvent) { return } - event.preventDefault(); - event.stopPropagation(); + event.preventDefault() + event.stopPropagation() - const toIndex = this.getDropTargetIndex(event); - this.clearDropTarget(); + const toIndex = this.getDropTargetIndex(event) + this.clearDropTarget() - let fromIndex; + let fromIndex if (tabEvent) { - fromIndex = parseInt(dataTransfer.getData("sortable-index")); - const paneIndex = parseInt(dataTransfer.getData("from-pane-index")); - const pane = atom.workspace.getPanes()[paneIndex]; - const view = pane.itemAtIndex(fromIndex); - pane.removeItem(view, false); - view.show(); - - view.toggleTabView(); - this.terminalViews.push(view); - if (view.statusIcon.isActive()) { view.open(); } - this.statusContainer.append(view.statusIcon); - fromIndex = this.terminalViews.length - 1; + fromIndex = parseInt(dataTransfer.getData('sortable-index')) + const paneIndex = parseInt(dataTransfer.getData('from-pane-index')) + const pane = atom.workspace.getPanes()[paneIndex] + const view = pane.itemAtIndex(fromIndex) + pane.removeItem(view, false) + view.show() + + view.toggleTabView() + this.terminalViews.push(view) + if (view.statusIcon.isActive()) { view.open() } + this.statusContainer.append(view.statusIcon) + fromIndex = this.terminalViews.length - 1 } else { - fromIndex = parseInt(dataTransfer.getData("from-index")); + fromIndex = parseInt(dataTransfer.getData('from-index')) } - this.updateOrder(fromIndex, toIndex); + this.updateOrder(fromIndex, toIndex) } - onDropTabBar(event, pane) { - const {dataTransfer} = event.originalEvent; - if (dataTransfer.getData("terminus-panel") !== "true") { return; } + onDropTabBar (event, pane) { + const { dataTransfer } = event.originalEvent + if (dataTransfer.getData('terminus-panel') !== 'true') { return } - event.preventDefault(); - event.stopPropagation(); - this.clearDropTarget(); + event.preventDefault() + event.stopPropagation() + this.clearDropTarget() - const fromIndex = parseInt(dataTransfer.getData("from-index")); - const view = this.terminalViews[fromIndex]; - view.css("height", ""); - view.terminal.element.style.height = atom.config.get("terminus.style.defaultPanelHeight"); + const fromIndex = parseInt(dataTransfer.getData('from-index')) + const view = this.terminalViews[fromIndex] + view.css('height', '') + view.terminal.element.style.height = atom.config.get('terminus.style.defaultPanelHeight') // const tabBar = $(event.target).closest('.tab-bar'); - view.toggleTabView(); - this.removeTerminalView(view); - this.statusContainer.children().eq(fromIndex).detach(); - view.statusIcon.removeTooltip(); + view.toggleTabView() + this.removeTerminalView(view) + this.statusContainer.children().eq(fromIndex).detach() + view.statusIcon.removeTooltip() - pane.addItem(view, {index: pane.getItems().length}); - pane.activateItem(view); + pane.addItem(view, { index: pane.getItems().length }) + pane.activateItem(view) - view.focus(); + view.focus() } - clearDropTarget() { - const element = this.find(".is-dragging"); - element.removeClass("is-dragging"); - this.removeDropTargetClasses(); - this.removePlaceholder(); + clearDropTarget () { + const element = this.find('.is-dragging') + element.removeClass('is-dragging') + this.removeDropTargetClasses() + this.removePlaceholder() } - removeDropTargetClasses() { - this.statusContainer.find(".is-drop-target").removeClass("is-drop-target"); - this.statusContainer.find(".drop-target-is-after").removeClass("drop-target-is-after"); + removeDropTargetClasses () { + this.statusContainer.find('.is-drop-target').removeClass('is-drop-target') + this.statusContainer.find('.drop-target-is-after').removeClass('drop-target-is-after') } - getDropTargetIndex(event) { - const target = $(event.target); - if (this.isPlaceholder(target)) { return; } + getDropTargetIndex (event) { + const target = $(event.target) + if (this.isPlaceholder(target)) { return } - const statusIcons = this.statusContainer.children(".terminus-status-icon"); - let element = target.closest(".terminus-status-icon"); - if (element.length === 0) { element = statusIcons.last(); } + const statusIcons = this.statusContainer.children('.terminus-status-icon') + let element = target.closest('.terminus-status-icon') + if (element.length === 0) { element = statusIcons.last() } - if (!element.length) { return 0; } + if (!element.length) { return 0 } - const elementCenter = element.offset().left + (element.width() / 2); + const elementCenter = element.offset().left + (element.width() / 2) if (event.originalEvent.pageX < elementCenter) { - return statusIcons.index(element); - } else if (element.next(".terminus-status-icon").length > 0) { - return statusIcons.index(element.next(".terminus-status-icon")); + return statusIcons.index(element) + } else if (element.next('.terminus-status-icon').length > 0) { + return statusIcons.index(element.next('.terminus-status-icon')) } else { - return statusIcons.index(element) + 1; + return statusIcons.index(element) + 1 } } - getPlaceholder() { - return this.placeholderEl ? this.placeholderEl : (this.placeholderEl = $("
  • ")); + getPlaceholder () { + return this.placeholderEl ? this.placeholderEl : (this.placeholderEl = $('
  • ')) } - removePlaceholder() { + removePlaceholder () { if (this.placeholderEl) { - this.placeholderEl.remove(); + this.placeholderEl.remove() } - this.placeholderEl = null; + this.placeholderEl = null } - isPlaceholder(element) { - return element.is(".placeholder"); + isPlaceholder (element) { + return element.is('.placeholder') } - iconAtIndex(index) { - return this.getStatusIcons().eq(index); + iconAtIndex (index) { + return this.getStatusIcons().eq(index) } - getStatusIcons() { - return this.statusContainer.children(".terminus-status-icon"); + getStatusIcons () { + return this.statusContainer.children('.terminus-status-icon') } - moveIconToIndex(icon, toIndex) { - const followingIcon = this.getStatusIcons()[toIndex]; - const container = this.statusContainer[0]; + moveIconToIndex (icon, toIndex) { + const followingIcon = this.getStatusIcons()[toIndex] + const container = this.statusContainer[0] if (followingIcon) { - container.insertBefore(icon, followingIcon); + container.insertBefore(icon, followingIcon) } else { - container.appendChild(icon); + container.appendChild(icon) } } - moveTerminalView(fromIndex, toIndex) { - const activeTerminal = this.getActiveTerminalView(); - const view = this.terminalViews.splice(fromIndex, 1)[0]; - this.terminalViews.splice(toIndex, 0, view); - this.setActiveTerminalView(activeTerminal); + moveTerminalView (fromIndex, toIndex) { + const activeTerminal = this.getActiveTerminalView() + const view = this.terminalViews.splice(fromIndex, 1)[0] + this.terminalViews.splice(toIndex, 0, view) + this.setActiveTerminalView(activeTerminal) } - updateOrder(fromIndex, toIndex) { - if (fromIndex === toIndex) { return; } - if (fromIndex < toIndex) { toIndex--; } + updateOrder (fromIndex, toIndex) { + if (fromIndex === toIndex) { return } + if (fromIndex < toIndex) { toIndex-- } - const icon = this.getStatusIcons().eq(fromIndex).detach(); - this.moveIconToIndex(icon.get(0), toIndex); - this.moveTerminalView(fromIndex, toIndex); - icon.addClass("inserted"); - icon.one("webkitAnimationEnd", () => icon.removeClass("inserted")); + const icon = this.getStatusIcons().eq(fromIndex).detach() + this.moveIconToIndex(icon.get(0), toIndex) + this.moveTerminalView(fromIndex, toIndex) + icon.addClass('inserted') + icon.one('webkitAnimationEnd', () => icon.removeClass('inserted')) } } -StatusBar.prototype.terminalViews = []; -StatusBar.prototype.activeTerminal = null; -StatusBar.prototype.returnFocus = null; +StatusBar.prototype.terminalViews = [] +StatusBar.prototype.activeTerminal = null +StatusBar.prototype.returnFocus = null -module.exports = StatusBar; +module.exports = StatusBar diff --git a/lib/status-icon.js b/lib/status-icon.js index 027585ae..1b918705 100644 --- a/lib/status-icon.js +++ b/lib/status-icon.js @@ -1,60 +1,59 @@ -let RenameDialog = null; +let RenameDialog = null class StatusIcon extends HTMLLIElement { - constructor(...args) { - super(...args); - this.setAttribute("is", "terminus-status-icon"); + constructor (...args) { + super(...args) + this.setAttribute('is', 'terminus-status-icon') } - initialize(terminalView) { - this.terminalView = terminalView; - this.classList.add("terminus-status-icon"); + initialize (terminalView) { + this.terminalView = terminalView + this.classList.add('terminus-status-icon') - this.icon = document.createElement("i"); - this.icon.classList.add("icon", "icon-terminal"); - this.appendChild(this.icon); + this.icon = document.createElement('i') + this.icon.classList.add('icon', 'icon-terminal') + this.appendChild(this.icon) - this.name = document.createElement("span"); - this.name.classList.add("name"); - this.appendChild(this.name); + this.name = document.createElement('span') + this.name.classList.add('name') + this.appendChild(this.name) - this.dataset.type = this.terminalView.constructor ? this.terminalView.constructor.name : undefined; + this.dataset.type = this.terminalView.constructor ? this.terminalView.constructor.name : undefined - this.addEventListener("click", ({which}) => { + this.addEventListener('click', ({ which }) => { if (which === 1) { - this.terminalView.toggle(); - return true; + this.terminalView.toggle() + return true } else if (which === 2) { - this.terminalView.destroy(); - return false; + this.terminalView.destroy() + return false } - }); + }) - this.setupTooltip(); + this.setupTooltip() } - setupTooltip() { - + setupTooltip () { const onMouseEnter = event => { - if (event.detail !== "terminus") { - this.updateTooltip(); + if (event.detail !== 'terminus') { + this.updateTooltip() } - }; + } this.mouseEnterSubscription = { dispose: () => { - this.removeEventListener("mouseenter", onMouseEnter); - this.mouseEnterSubscription = null; + this.removeEventListener('mouseenter', onMouseEnter) + this.mouseEnterSubscription = null } - }; + } - this.addEventListener("mouseenter", onMouseEnter); + this.addEventListener('mouseenter', onMouseEnter) } - updateTooltip() { - this.removeTooltip(); + updateTooltip () { + this.removeTooltip() - const process = this.terminalView.getTerminalTitle(); + const process = this.terminalView.getTerminalTitle() if (process) { this.tooltip = atom.tooltips.add(this, { title: process, @@ -63,67 +62,67 @@ class StatusIcon extends HTMLLIElement { show: 1000, hide: 100 } - }); + }) } - this.dispatchEvent(new CustomEvent("mouseenter", {bubbles: true, detail: "terminus"})); + this.dispatchEvent(new CustomEvent('mouseenter', { bubbles: true, detail: 'terminus' })) } - removeTooltip() { - if (this.tooltip) { this.tooltip.dispose(); } - this.tooltip = null; + removeTooltip () { + if (this.tooltip) { this.tooltip.dispose() } + this.tooltip = null } - destroy() { - this.removeTooltip(); - if (this.mouseEnterSubscription) { this.mouseEnterSubscription.dispose(); } - this.remove(); + destroy () { + this.removeTooltip() + if (this.mouseEnterSubscription) { this.mouseEnterSubscription.dispose() } + this.remove() } - activate() { - this.classList.add("active"); - this.active = true; + activate () { + this.classList.add('active') + this.active = true } - deactivate() { - this.classList.remove("active"); - this.active = false; + deactivate () { + this.classList.remove('active') + this.active = false } - toggle() { + toggle () { if (this.active) { - this.classList.remove("active"); + this.classList.remove('active') } else { - this.classList.add("active"); + this.classList.add('active') } - this.active = !this.active; + this.active = !this.active } - isActive() { - return this.active; + isActive () { + return this.active } - rename() { - if (!RenameDialog) { RenameDialog = require("./rename-dialog"); } - const dialog = new RenameDialog(this); - dialog.attach(); + rename () { + if (!RenameDialog) { RenameDialog = require('./rename-dialog') } + const dialog = new RenameDialog(this) + dialog.attach() } - getName() { - return this.name.textContent.substring(1); + getName () { + return this.name.textContent.substring(1) } - updateName(name) { + updateName (name) { if (name !== this.getName()) { - if (name) { name = " " + name; } - this.name.innerHTML = name; - this.terminalView.emit("did-change-title"); + if (name) { name = ' ' + name } + this.name.innerHTML = name + this.terminalView.emit('did-change-title') } } } -StatusIcon.prototype.active = false; +StatusIcon.prototype.active = false -customElements.define("terminus-status-icon", StatusIcon, {extends: "li"}); +customElements.define('terminus-status-icon', StatusIcon, { extends: 'li' }) -module.exports = StatusIcon; +module.exports = StatusIcon diff --git a/lib/terminus.js b/lib/terminus.js index 626305b6..b6a1d15a 100644 --- a/lib/terminus.js +++ b/lib/terminus.js @@ -1,431 +1,431 @@ module.exports = { statusBar: null, - activate() {}, + activate () {}, - deactivate() { + deactivate () { if (this.statusBarTile) { - this.statusBarTile.destroy(); + this.statusBarTile.destroy() } - this.statusBarTile = null; + this.statusBarTile = null }, - consumeStatusBar(statusBarProvider) { - this.statusBarTile = new (require("./status-bar"))(statusBarProvider); + consumeStatusBar (statusBarProvider) { + this.statusBarTile = new (require('./status-bar'))(statusBarProvider) }, - provideTerminus() { + provideTerminus () { return { - updateProcessEnv(variables) { + updateProcessEnv (variables) { for (const name in variables) { - process.env[name] = variables[name]; + process.env[name] = variables[name] } }, run: (commands) => { - return this.statusBarTile.runCommandInNewTerminal(commands); + return this.statusBarTile.runCommandInNewTerminal(commands) }, getTerminalViews: () => { - return this.statusBarTile.terminalViews; + return this.statusBarTile.terminalViews }, open: () => { - return this.statusBarTile.runNewTerminal(); + return this.statusBarTile.runNewTerminal() } - }; + } }, config: { toggles: { - type: "object", + type: 'object', order: 1, properties: { autoClose: { - title: "Close Terminal on Exit", - description: "Should the terminal close if the shell exits?", - type: "boolean", + title: 'Close Terminal on Exit', + description: 'Should the terminal close if the shell exits?', + type: 'boolean', default: true }, cursorBlink: { - title: "Cursor Blink", - description: "Should the cursor blink when the terminal is active?", - type: "boolean", + title: 'Cursor Blink', + description: 'Should the cursor blink when the terminal is active?', + type: 'boolean', default: true }, runInsertedText: { - title: "Run Inserted Text", - description: "Run text inserted via `terminus:insert-text` as a command? **This will append an end-of-line character to input.**", - type: "boolean", + title: 'Run Inserted Text', + description: 'Run text inserted via `terminus:insert-text` as a command? **This will append an end-of-line character to input.**', + type: 'boolean', default: true }, selectToCopy: { - title: "Select To Copy", - description: "Copies text to clipboard when selection happens.", - type: "boolean", + title: 'Select To Copy', + description: 'Copies text to clipboard when selection happens.', + type: 'boolean', default: true }, loginShell: { - title: "Login Shell", - description: "Use --login on zsh and bash.", - type: "boolean", + title: 'Login Shell', + description: 'Use --login on zsh and bash.', + type: 'boolean', default: true }, showToolbar: { - title: "Show Toolbar", - description: "Show toolbar above terminal window.", - type: "boolean", + title: 'Show Toolbar', + description: 'Show toolbar above terminal window.', + type: 'boolean', default: true } } }, core: { - type: "object", + type: 'object', order: 2, properties: { autoRunCommand: { - title: "Auto Run Command", - description: "Command to run on terminal initialization.", - type: "string", - default: "" + title: 'Auto Run Command', + description: 'Command to run on terminal initialization.', + type: 'string', + default: '' }, mapTerminalsTo: { - title: "Map Terminals To", - description: "Map terminals to each file or folder. Default is no action or mapping at all. **Restart required.**", - type: "string", - default: "None", - enum: ["None", "File", "Folder"] + title: 'Map Terminals To', + description: 'Map terminals to each file or folder. Default is no action or mapping at all. **Restart required.**', + type: 'string', + default: 'None', + enum: ['None', 'File', 'Folder'] }, mapTerminalsToAutoOpen: { - title: "Auto Open a New Terminal (For Terminal Mapping)", - description: "Should a new terminal be opened for new items? **Note:** This works in conjunction with `Map Terminals To` above.", - type: "boolean", + title: 'Auto Open a New Terminal (For Terminal Mapping)', + description: 'Should a new terminal be opened for new items? **Note:** This works in conjunction with `Map Terminals To` above.', + type: 'boolean', default: false }, scrollback: { - title: "Scroll Back", - description: "How many lines of history should be kept?", - type: "integer", + title: 'Scroll Back', + description: 'How many lines of history should be kept?', + type: 'integer', default: 1000 }, shell: { - title: "Shell Override", - description: "Override the default shell instance to launch.", - type: "string", - default: (process.platform === "win32" - ? require("path").resolve(process.env.SystemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe") - : process.env.SHELL || "/bin/bash") + title: 'Shell Override', + description: 'Override the default shell instance to launch.', + type: 'string', + default: (process.platform === 'win32' + ? require('path').resolve(process.env.SystemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe') + : process.env.SHELL || '/bin/bash') }, shellArguments: { - title: "Shell Arguments", - description: "Specify some arguments to use when launching the shell.", - type: "string", - default: "" + title: 'Shell Arguments', + description: 'Specify some arguments to use when launching the shell.', + type: 'string', + default: '' }, shellEnv: { - title: "Shell Environment Variables", - description: "Specify some additional environment variables, space separated with the form `VAR=VALUE`", - type: "string", - default: "" + title: 'Shell Environment Variables', + description: 'Specify some additional environment variables, space separated with the form `VAR=VALUE`', + type: 'string', + default: '' }, workingDirectory: { - title: "Working Directory", - description: "Which directory should be the present working directory when a new terminal is made?", - type: "string", - default: "Project", - enum: ["Home", "Project", "Active File"] + title: 'Working Directory', + description: 'Which directory should be the present working directory when a new terminal is made?', + type: 'string', + default: 'Project', + enum: ['Home', 'Project', 'Active File'] } } }, style: { - type: "object", + type: 'object', order: 3, properties: { animationSpeed: { - title: "Animation Speed", - description: "How fast should the window animate?", - type: "number", - default: "1", - minimum: "0", - maximum: "100" + title: 'Animation Speed', + description: 'How fast should the window animate?', + type: 'number', + default: '1', + minimum: '0', + maximum: '100' }, fontFamily: { - title: "Font Family", + title: 'Font Family', description: "Override the terminal's default font family. **You must use a [monospaced font](https://en.wikipedia.org/wiki/List_of_typefaces#Monospace)!**", - type: "string", - default: "" + type: 'string', + default: '' }, fontSize: { - title: "Font Size", + title: 'Font Size', description: "Override the terminal's default font size.", - type: "string", - default: "" + type: 'string', + default: '' }, defaultPanelHeight: { - title: "Default Panel Height", - description: "Default height of a terminal panel. **You may enter a value in px, em, or %.**", - type: "string", - default: "300px" + title: 'Default Panel Height', + description: 'Default height of a terminal panel. **You may enter a value in px, em, or %.**', + type: 'string', + default: '300px' }, theme: { - title: "Theme", - description: "Select a theme for the terminal.", - type: "string", - default: "standard", + title: 'Theme', + description: 'Select a theme for the terminal.', + type: 'string', + default: 'standard', enum: [ - "standard", - "homebrew", - "atom-dark", - "atom-light", - "one-dark", - "one-light", - "base16-tomorrow-dark", - "base16-tomorrow-light", - "solarized-dark", - "solarized-light", - "inverse", - "linux", - "grass", - "man-page", - "novel", - "ocean", - "pro", - "red", - "red-sands", - "silver-aerogel", - "solid-colors", - "dracula", - "christmas", - "predawn", - "city-lights" + 'standard', + 'homebrew', + 'atom-dark', + 'atom-light', + 'one-dark', + 'one-light', + 'base16-tomorrow-dark', + 'base16-tomorrow-light', + 'solarized-dark', + 'solarized-light', + 'inverse', + 'linux', + 'grass', + 'man-page', + 'novel', + 'ocean', + 'pro', + 'red', + 'red-sands', + 'silver-aerogel', + 'solid-colors', + 'dracula', + 'christmas', + 'predawn', + 'city-lights' ] } } }, ansiColors: { - type: "object", + type: 'object', order: 4, properties: { normal: { - type: "object", + type: 'object', order: 1, properties: { black: { - title: "Black", - description: "Black color used for terminal ANSI color set.", - type: "color", - default: "#000000" + title: 'Black', + description: 'Black color used for terminal ANSI color set.', + type: 'color', + default: '#000000' }, red: { - title: "Red", - description: "Red color used for terminal ANSI color set.", - type: "color", - default: "#cd0000" + title: 'Red', + description: 'Red color used for terminal ANSI color set.', + type: 'color', + default: '#cd0000' }, green: { - title: "Green", - description: "Green color used for terminal ANSI color set.", - type: "color", - default: "#00cd00" + title: 'Green', + description: 'Green color used for terminal ANSI color set.', + type: 'color', + default: '#00cd00' }, yellow: { - title: "Yellow", - description: "Yellow color used for terminal ANSI color set.", - type: "color", - default: "#cdcd00" + title: 'Yellow', + description: 'Yellow color used for terminal ANSI color set.', + type: 'color', + default: '#cdcd00' }, blue: { - title: "Blue", - description: "Blue color used for terminal ANSI color set.", - type: "color", - default: "#0000cd" + title: 'Blue', + description: 'Blue color used for terminal ANSI color set.', + type: 'color', + default: '#0000cd' }, magenta: { - title: "Magenta", - description: "Magenta color used for terminal ANSI color set.", - type: "color", - default: "#cd00cd" + title: 'Magenta', + description: 'Magenta color used for terminal ANSI color set.', + type: 'color', + default: '#cd00cd' }, cyan: { - title: "Cyan", - description: "Cyan color used for terminal ANSI color set.", - type: "color", - default: "#00cdcd" + title: 'Cyan', + description: 'Cyan color used for terminal ANSI color set.', + type: 'color', + default: '#00cdcd' }, white: { - title: "White", - description: "White color used for terminal ANSI color set.", - type: "color", - default: "#e5e5e5" + title: 'White', + description: 'White color used for terminal ANSI color set.', + type: 'color', + default: '#e5e5e5' } } }, zBright: { - type: "object", + type: 'object', order: 2, properties: { brightBlack: { - title: "Bright Black", - description: "Bright black color used for terminal ANSI color set.", - type: "color", - default: "#7f7f7f" + title: 'Bright Black', + description: 'Bright black color used for terminal ANSI color set.', + type: 'color', + default: '#7f7f7f' }, brightRed: { - title: "Bright Red", - description: "Bright red color used for terminal ANSI color set.", - type: "color", - default: "#ff0000" + title: 'Bright Red', + description: 'Bright red color used for terminal ANSI color set.', + type: 'color', + default: '#ff0000' }, brightGreen: { - title: "Bright Green", - description: "Bright green color used for terminal ANSI color set.", - type: "color", - default: "#00ff00" + title: 'Bright Green', + description: 'Bright green color used for terminal ANSI color set.', + type: 'color', + default: '#00ff00' }, brightYellow: { - title: "Bright Yellow", - description: "Bright yellow color used for terminal ANSI color set.", - type: "color", - default: "#ffff00" + title: 'Bright Yellow', + description: 'Bright yellow color used for terminal ANSI color set.', + type: 'color', + default: '#ffff00' }, brightBlue: { - title: "Bright Blue", - description: "Bright blue color used for terminal ANSI color set.", - type: "color", - default: "#0000ff" + title: 'Bright Blue', + description: 'Bright blue color used for terminal ANSI color set.', + type: 'color', + default: '#0000ff' }, brightMagenta: { - title: "Bright Magenta", - description: "Bright magenta color used for terminal ANSI color set.", - type: "color", - default: "#ff00ff" + title: 'Bright Magenta', + description: 'Bright magenta color used for terminal ANSI color set.', + type: 'color', + default: '#ff00ff' }, brightCyan: { - title: "Bright Cyan", - description: "Bright cyan color used for terminal ANSI color set.", - type: "color", - default: "#00ffff" + title: 'Bright Cyan', + description: 'Bright cyan color used for terminal ANSI color set.', + type: 'color', + default: '#00ffff' }, brightWhite: { - title: "Bright White", - description: "Bright white color used for terminal ANSI color set.", - type: "color", - default: "#fff" + title: 'Bright White', + description: 'Bright white color used for terminal ANSI color set.', + type: 'color', + default: '#fff' } } } } }, iconColors: { - type: "object", + type: 'object', order: 5, properties: { red: { - title: "Status Icon Red", - description: "Red color used for status icon.", - type: "color", - default: "red" + title: 'Status Icon Red', + description: 'Red color used for status icon.', + type: 'color', + default: 'red' }, orange: { - title: "Status Icon Orange", - description: "Orange color used for status icon.", - type: "color", - default: "orange" + title: 'Status Icon Orange', + description: 'Orange color used for status icon.', + type: 'color', + default: 'orange' }, yellow: { - title: "Status Icon Yellow", - description: "Yellow color used for status icon.", - type: "color", - default: "yellow" + title: 'Status Icon Yellow', + description: 'Yellow color used for status icon.', + type: 'color', + default: 'yellow' }, green: { - title: "Status Icon Green", - description: "Green color used for status icon.", - type: "color", - default: "green" + title: 'Status Icon Green', + description: 'Green color used for status icon.', + type: 'color', + default: 'green' }, blue: { - title: "Status Icon Blue", - description: "Blue color used for status icon.", - type: "color", - default: "blue" + title: 'Status Icon Blue', + description: 'Blue color used for status icon.', + type: 'color', + default: 'blue' }, purple: { - title: "Status Icon Purple", - description: "Purple color used for status icon.", - type: "color", - default: "purple" + title: 'Status Icon Purple', + description: 'Purple color used for status icon.', + type: 'color', + default: 'purple' }, pink: { - title: "Status Icon Pink", - description: "Pink color used for status icon.", - type: "color", - default: "hotpink" + title: 'Status Icon Pink', + description: 'Pink color used for status icon.', + type: 'color', + default: 'hotpink' }, cyan: { - title: "Status Icon Cyan", - description: "Cyan color used for status icon.", - type: "color", - default: "cyan" + title: 'Status Icon Cyan', + description: 'Cyan color used for status icon.', + type: 'color', + default: 'cyan' }, magenta: { - title: "Status Icon Magenta", - description: "Magenta color used for status icon.", - type: "color", - default: "magenta" + title: 'Status Icon Magenta', + description: 'Magenta color used for status icon.', + type: 'color', + default: 'magenta' } } }, customTexts: { - type: "object", + type: 'object', order: 6, properties: { customText1: { - title: "Custom text 1", - description: "Text to paste when calling terminus:insert-custom-text-1, $S is replaced by selection, $F is replaced by file name, $D is replaced by file directory, $L is replaced by line number of cursor, $$ is replaced by $", - type: "string", - default: "" + title: 'Custom text 1', + description: 'Text to paste when calling terminus:insert-custom-text-1, $S is replaced by selection, $F is replaced by file name, $D is replaced by file directory, $L is replaced by line number of cursor, $$ is replaced by $', + type: 'string', + default: '' }, customText2: { - title: "Custom text 2", - description: "Text to paste when calling terminus:insert-custom-text-2", - type: "string", - default: "" + title: 'Custom text 2', + description: 'Text to paste when calling terminus:insert-custom-text-2', + type: 'string', + default: '' }, customText3: { - title: "Custom text 3", - description: "Text to paste when calling terminus:insert-custom-text-3", - type: "string", - default: "" + title: 'Custom text 3', + description: 'Text to paste when calling terminus:insert-custom-text-3', + type: 'string', + default: '' }, customText4: { - title: "Custom text 4", - description: "Text to paste when calling terminus:insert-custom-text-4", - type: "string", - default: "" + title: 'Custom text 4', + description: 'Text to paste when calling terminus:insert-custom-text-4', + type: 'string', + default: '' }, customText5: { - title: "Custom text 5", - description: "Text to paste when calling terminus:insert-custom-text-5", - type: "string", - default: "" + title: 'Custom text 5', + description: 'Text to paste when calling terminus:insert-custom-text-5', + type: 'string', + default: '' }, customText6: { - title: "Custom text 6", - description: "Text to paste when calling terminus:insert-custom-text-6", - type: "string", - default: "" + title: 'Custom text 6', + description: 'Text to paste when calling terminus:insert-custom-text-6', + type: 'string', + default: '' }, customText7: { - title: "Custom text 7", - description: "Text to paste when calling terminus:insert-custom-text-7", - type: "string", - default: "" + title: 'Custom text 7', + description: 'Text to paste when calling terminus:insert-custom-text-7', + type: 'string', + default: '' }, customText8: { - title: "Custom text 8", - description: "Text to paste when calling terminus:insert-custom-text-8", - type: "string", - default: "" + title: 'Custom text 8', + description: 'Text to paste when calling terminus:insert-custom-text-8', + type: 'string', + default: '' } } } } -}; +} diff --git a/lib/view.js b/lib/view.js index 31197acf..e5b7d69f 100644 --- a/lib/view.js +++ b/lib/view.js @@ -1,730 +1,735 @@ -const {Task, CompositeDisposable, Emitter} = require("atom"); -const {$, View} = require("atom-space-pen-views"); +const { Task, CompositeDisposable, Emitter } = require('atom') +const { $, View } = require('atom-space-pen-views') -const Pty = require.resolve("./process"); -const Terminal = require("term.js"); -let InputDialog = null; +const Pty = require.resolve('./process') +const Terminal = require('term.js') +let InputDialog = null -const path = require("path"); -const os = require("os"); +const path = require('path') +const os = require('os') -let lastOpenedView = null; -let lastActiveElement = null; +let lastOpenedView = null +let lastActiveElement = null class TerminusView extends View { - static content() { - this.div({class: "terminus terminal-view", outlet: "terminusView"}, () => { - this.div({class: "panel-divider", outlet: "panelDivider"}); - this.section({class: "input-block"}, () => { - this.div({outlet: "toolbar", class: "btn-toolbar"}, () => { - this.div({class: "btn-group"}, () => { - this.button({outlet: "inputBtn", class: "btn icon icon-keyboard", click: "inputDialog"}); - }); - this.div({class: "btn-group right"}, () => { - this.button({outlet: "hideBtn", class: "btn icon icon-chevron-down", click: "hide"}); - this.button({outlet: "maximizeBtn", class: "btn icon icon-screen-full", click: "maximize"}); - this.button({outlet: "closeBtn", class: "btn icon icon-x", click: "destroy"}); - }); - }); - }); - this.div({class: "xterm", outlet: "xterm"}); - }); - } - - static getFocusedTerminal() { - return Terminal.Terminal.focus; - } - - initialize(id, pwd, statusIcon, statusBar, shell, args = [], env = {}, autoRun = []) { - this.id = id; - this.pwd = pwd; - this.statusIcon = statusIcon; - this.statusBar = statusBar; - this.shell = shell; - this.args = args; - this.env = env; - this.autoRun = autoRun; - this.subscriptions = new CompositeDisposable; - this.emitter = new Emitter; - - this.focus = this.focus.bind(this); - this.onWindowResize = this.onWindowResize.bind(this); - this.resizeStarted = this.resizeStarted.bind(this); - this.resizePanel = this.resizePanel.bind(this); - this.resizeStopped = this.resizeStopped.bind(this); - this.setAnimationSpeed = this.setAnimationSpeed.bind(this); - this.updateToolbarVisibility = this.updateToolbarVisibility.bind(this); - this.recieveItemOrFile = this.recieveItemOrFile.bind(this); - - this.subscriptions.add(atom.tooltips.add(this.closeBtn, {title: "Close"})); - this.subscriptions.add(atom.tooltips.add(this.hideBtn, {title: "Hide"})); - this.subscriptions.add(this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, {title: "Fullscreen"})); - this.inputBtn.tooltip = atom.tooltips.add(this.inputBtn, {title: "Insert Text"}); - - this.prevHeight = atom.config.get("terminus.style.defaultPanelHeight"); - if (this.prevHeight.indexOf("%") > 0) { - const percent = Math.abs(Math.min(parseFloat(this.prevHeight) / 100.0, 1)); - const bottomHeight = $("atom-panel.bottom").children(".terminal-view").height() || 0; - this.prevHeight = percent * ($(".item-views").height() + bottomHeight); + static content () { + this.div({ class: 'terminus terminal-view', outlet: 'terminusView' }, () => { + this.div({ class: 'panel-divider', outlet: 'panelDivider' }) + this.section({ class: 'input-block' }, () => { + this.div({ outlet: 'toolbar', class: 'btn-toolbar' }, () => { + this.div({ class: 'btn-group' }, () => { + this.button({ outlet: 'inputBtn', class: 'btn icon icon-keyboard', click: 'inputDialog' }) + }) + this.div({ class: 'btn-group right' }, () => { + this.button({ outlet: 'hideBtn', class: 'btn icon icon-chevron-down', click: 'hide' }) + this.button({ outlet: 'maximizeBtn', class: 'btn icon icon-screen-full', click: 'maximize' }) + this.button({ outlet: 'closeBtn', class: 'btn icon icon-x', click: 'destroy' }) + }) + }) + }) + this.div({ class: 'xterm', outlet: 'xterm' }) + }) + } + + static getFocusedTerminal () { + return Terminal.Terminal.focus + } + + initialize (id, pwd, statusIcon, statusBar, shell, args = [], env = {}, autoRun = []) { + this.id = id + this.pwd = pwd + this.statusIcon = statusIcon + this.statusBar = statusBar + this.shell = shell + this.args = args + this.env = env + this.autoRun = autoRun + this.subscriptions = new CompositeDisposable() + this.emitter = new Emitter() + + this.focus = this.focus.bind(this) + this.onWindowResize = this.onWindowResize.bind(this) + this.resizeStarted = this.resizeStarted.bind(this) + this.resizePanel = this.resizePanel.bind(this) + this.resizeStopped = this.resizeStopped.bind(this) + this.setAnimationSpeed = this.setAnimationSpeed.bind(this) + this.updateToolbarVisibility = this.updateToolbarVisibility.bind(this) + this.recieveItemOrFile = this.recieveItemOrFile.bind(this) + + this.subscriptions.add(atom.tooltips.add(this.closeBtn, { title: 'Close' })) + this.subscriptions.add(atom.tooltips.add(this.hideBtn, { title: 'Hide' })) + this.subscriptions.add(this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, { title: 'Fullscreen' })) + this.inputBtn.tooltip = atom.tooltips.add(this.inputBtn, { title: 'Insert Text' }) + + this.prevHeight = atom.config.get('terminus.style.defaultPanelHeight') + if (this.prevHeight.indexOf('%') > 0) { + const percent = Math.abs(Math.min(parseFloat(this.prevHeight) / 100.0, 1)) + const bottomHeight = $('atom-panel.bottom').children('.terminal-view').height() || 0 + this.prevHeight = percent * ($('.item-views').height() + bottomHeight) } - this.xterm.height(0); + this.xterm.height(0) - this.setAnimationSpeed(); - this.subscriptions.add(atom.config.onDidChange("terminus.style.animationSpeed", this.setAnimationSpeed)); + this.setAnimationSpeed() + this.subscriptions.add(atom.config.onDidChange('terminus.style.animationSpeed', this.setAnimationSpeed)) - this.updateToolbarVisibility(); - this.subscriptions.add(atom.config.onDidChange("terminus.toggles.showToolbar", this.updateToolbarVisibility)); + this.updateToolbarVisibility() + this.subscriptions.add(atom.config.onDidChange('terminus.toggles.showToolbar', this.updateToolbarVisibility)) const override = (event) => { - if (event.originalEvent.dataTransfer.getData("terminus") === "true") { return; } - event.preventDefault(); - event.stopPropagation(); - }; + if (event.originalEvent.dataTransfer.getData('terminus') === 'true') { return } + event.preventDefault() + event.stopPropagation() + } - this.xterm.on("mouseup", event => { + this.xterm.on('mouseup', event => { if (event.which !== 3) { - let text = window.getSelection().toString(); - if (atom.config.get("terminus.toggles.selectToCopy") && text) { - const rawLines = text.split(/\r?\n/g); - const lines = rawLines.map(line => line.replace(/\s/g, " ").trimRight()); - text = lines.join("\n"); - atom.clipboard.write(text); + let text = window.getSelection().toString() + if (atom.config.get('terminus.toggles.selectToCopy') && text) { + const rawLines = text.split(/\r?\n/g) + const lines = rawLines.map(line => line.replace(/\s/g, ' ').trimRight()) + text = lines.join('\n') + atom.clipboard.write(text) } if (!text) { - this.focus(); + this.focus() } } - }); - this.xterm.on("dragenter", override); - this.xterm.on("dragover", override); - this.xterm.on("drop", this.recieveItemOrFile); - - this.on("focus", this.focus); - this.subscriptions.add({dispose: () => { - this.off("focus", this.focus); - }}); - - if (/zsh|bash/.test(this.shell) && (this.args.indexOf("--login") === -1) && (Pty.platform !== "win32") && atom.config.get("terminus.toggles.loginShell")) { - this.args.unshift("--login"); + }) + this.xterm.on('dragenter', override) + this.xterm.on('dragover', override) + this.xterm.on('drop', this.recieveItemOrFile) + + this.on('focus', this.focus) + this.subscriptions.add({ + dispose: () => { + this.off('focus', this.focus) + } + }) + + if (/zsh|bash/.test(this.shell) && (this.args.indexOf('--login') === -1) && (Pty.platform !== 'win32') && atom.config.get('terminus.toggles.loginShell')) { + this.args.unshift('--login') } } - attach() { - if (this.panel) { return; } - this.panel = atom.workspace.addBottomPanel({item: this, visible: false}); + attach () { + if (this.panel) { return } + this.panel = atom.workspace.addBottomPanel({ item: this, visible: false }) } - setAnimationSpeed() { - this.animationSpeed = atom.config.get("terminus.style.animationSpeed"); - if (this.animationSpeed === 0) { this.animationSpeed = 100; } + setAnimationSpeed () { + this.animationSpeed = atom.config.get('terminus.style.animationSpeed') + if (this.animationSpeed === 0) { this.animationSpeed = 100 } - this.xterm.css("transition", `height ${0.25 / this.animationSpeed}s linear`); + this.xterm.css('transition', `height ${0.25 / this.animationSpeed}s linear`) } - updateToolbarVisibility() { - this.showToolbar = atom.config.get("terminus.toggles.showToolbar"); + updateToolbarVisibility () { + this.showToolbar = atom.config.get('terminus.toggles.showToolbar') if (this.showToolbar) { - this.toolbar.css("display", "block"); + this.toolbar.css('display', 'block') } else { - this.toolbar.css("display", "none"); + this.toolbar.css('display', 'none') } } - recieveItemOrFile(event) { - event.preventDefault(); - event.stopPropagation(); - const {dataTransfer} = event.originalEvent; + recieveItemOrFile (event) { + event.preventDefault() + event.stopPropagation() + const { dataTransfer } = event.originalEvent - if (dataTransfer.getData("atom-event") === "true") { - const filePath = dataTransfer.getData("text/plain"); + if (dataTransfer.getData('atom-event') === 'true') { + const filePath = dataTransfer.getData('text/plain') if (filePath) { - this.input(`${filePath} `); + this.input(`${filePath} `) } } else { - const filePath = dataTransfer.getData("initialPath"); + const filePath = dataTransfer.getData('initialPath') if (filePath) { - this.input(`${filePath} `); + this.input(`${filePath} `) } else if (dataTransfer.files.length > 0) { - dataTransfer.files.forEach(file => this.input(`${file.path} `)); + dataTransfer.files.forEach(file => this.input(`${file.path} `)) } } } - forkPtyProcess() { + forkPtyProcess () { return Task.once(Pty, path.resolve(this.pwd), this.shell, this.args, this.env, () => { - this.input = function() {}; - this.resize = function() {}; - }); + this.input = function () {} + this.resize = function () {} + }) } - getId() { - return this.id; + getId () { + return this.id } - displayTerminal() { - const {cols, rows} = this.getDimensions(); - this.ptyProcess = this.forkPtyProcess(); + displayTerminal () { + const { cols, rows } = this.getDimensions() + this.ptyProcess = this.forkPtyProcess() this.terminal = new Terminal({ cursorBlink: false, - scrollback: atom.config.get("terminus.core.scrollback"), + scrollback: atom.config.get('terminus.core.scrollback'), cols, rows - }); + }) - this.attachListeners(); - this.attachResizeEvents(); - this.attachWindowEvents(); - this.terminal.open(this.xterm.get(0)); + this.attachListeners() + this.attachResizeEvents() + this.attachWindowEvents() + this.terminal.open(this.xterm.get(0)) } - attachListeners() { - this.ptyProcess.on("terminus:data", data => { - this.terminal.write(data); - }); + attachListeners () { + this.ptyProcess.on('terminus:data', data => { + this.terminal.write(data) + }) - this.ptyProcess.on("terminus:exit", () => { - if (atom.config.get("terminus.toggles.autoClose")) { - this.destroy(); + this.ptyProcess.on('terminus:exit', () => { + if (atom.config.get('terminus.toggles.autoClose')) { + this.destroy() } - }); + }) - this.terminal.end = () => this.destroy(); + this.terminal.end = () => this.destroy() - this.terminal.on("data", data => { - this.input(data); - }); + this.terminal.on('data', data => { + this.input(data) + }) - this.ptyProcess.on("terminus:title", title => { - this.process = title; - }); - this.terminal.on("title", title => { - this.title = title; - }); + this.ptyProcess.on('terminus:title', title => { + this.process = title + }) + this.terminal.on('title', title => { + this.title = title + }) - this.terminal.once("open", () => { - this.applyStyle(); - this.resizeTerminalToView(); + this.terminal.once('open', () => { + this.applyStyle() + this.resizeTerminalToView() - if (!this.ptyProcess.childProcess) { return; } - const autoRunCommand = atom.config.get("terminus.core.autoRunCommand"); - if (autoRunCommand) { this.input(`${autoRunCommand}${os.EOL}`); } - this.autoRun.forEach(command => this.input(`${command}${os.EOL}`)); - }); + if (!this.ptyProcess.childProcess) { return } + const autoRunCommand = atom.config.get('terminus.core.autoRunCommand') + if (autoRunCommand) { this.input(`${autoRunCommand}${os.EOL}`) } + this.autoRun.forEach(command => this.input(`${command}${os.EOL}`)) + }) } - destroy() { - this.subscriptions.dispose(); - this.statusIcon.destroy(); - this.statusBar.removeTerminalView(this); - this.detachResizeEvents(); - this.detachWindowEvents(); + destroy () { + this.subscriptions.dispose() + this.statusIcon.destroy() + this.statusBar.removeTerminalView(this) + this.detachResizeEvents() + this.detachWindowEvents() if (this.panel.isVisible()) { - this.hide(); - this.onTransitionEnd(() => this.panel.destroy()); + this.hide() + this.onTransitionEnd(() => this.panel.destroy()) } else { - this.panel.destroy(); + this.panel.destroy() } if (this.statusIcon && this.statusIcon.parentNode) { - this.statusIcon.parentNode.removeChild(this.statusIcon); + this.statusIcon.parentNode.removeChild(this.statusIcon) } if (this.ptyProcess) { - this.ptyProcess.terminate(); + this.ptyProcess.terminate() } if (this.terminal) { - this.terminal.destroy(); + this.terminal.destroy() } } - maximize() { - this.subscriptions.remove(this.maximizeBtn.tooltip); - this.maximizeBtn.tooltip.dispose(); + maximize () { + this.subscriptions.remove(this.maximizeBtn.tooltip) + this.maximizeBtn.tooltip.dispose() - this.maxHeight = this.prevHeight + atom.workspace.getCenter().paneContainer.element.offsetHeight; - const btn = this.maximizeBtn.children("span"); - this.onTransitionEnd(() => this.focus()); + this.maxHeight = this.prevHeight + atom.workspace.getCenter().paneContainer.element.offsetHeight + const btn = this.maximizeBtn.children('span') + this.onTransitionEnd(() => this.focus()) if (this.maximized) { - this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, {title: "Fullscreen"}); - this.subscriptions.add(this.maximizeBtn.tooltip); - this.adjustHeight(this.prevHeight); - btn.removeClass("icon-screen-normal").addClass("icon-screen-full"); - this.maximized = false; + this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, { title: 'Fullscreen' }) + this.subscriptions.add(this.maximizeBtn.tooltip) + this.adjustHeight(this.prevHeight) + btn.removeClass('icon-screen-normal').addClass('icon-screen-full') + this.maximized = false } else { - this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, {title: "Normal"}); - this.subscriptions.add(this.maximizeBtn.tooltip); - this.adjustHeight(this.maxHeight); - btn.removeClass("icon-screen-full").addClass("icon-screen-normal"); - this.maximized = true; + this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, { title: 'Normal' }) + this.subscriptions.add(this.maximizeBtn.tooltip) + this.adjustHeight(this.maxHeight) + btn.removeClass('icon-screen-full').addClass('icon-screen-normal') + this.maximized = true } } - open() { + open () { if (!lastActiveElement) { - lastActiveElement = $(document.activeElement); + lastActiveElement = $(document.activeElement) } if (lastOpenedView && (lastOpenedView !== this)) { if (lastOpenedView.maximized) { - this.subscriptions.remove(this.maximizeBtn.tooltip); - this.maximizeBtn.tooltip.dispose(); - const icon = this.maximizeBtn.children("span"); - - this.maxHeight = lastOpenedView.maxHeight; - this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, {title: "Normal"}); - this.subscriptions.add(this.maximizeBtn.tooltip); - icon.removeClass("icon-screen-full").addClass("icon-screen-normal"); - this.maximized = true; + this.subscriptions.remove(this.maximizeBtn.tooltip) + this.maximizeBtn.tooltip.dispose() + const icon = this.maximizeBtn.children('span') + + this.maxHeight = lastOpenedView.maxHeight + this.maximizeBtn.tooltip = atom.tooltips.add(this.maximizeBtn, { title: 'Normal' }) + this.subscriptions.add(this.maximizeBtn.tooltip) + icon.removeClass('icon-screen-full').addClass('icon-screen-normal') + this.maximized = true } - lastOpenedView.hide(); + lastOpenedView.hide() } - lastOpenedView = this; - this.statusBar.setActiveTerminalView(this); - this.statusIcon.activate(); + lastOpenedView = this + this.statusBar.setActiveTerminalView(this) + this.statusIcon.activate() this.onTransitionEnd(() => { if (!this.opened) { - this.opened = true; - this.displayTerminal(); - this.prevHeight = this.nearestRow(this.xterm.height()); - this.xterm.height(this.prevHeight); - this.emit("terminus:terminal-open"); + this.opened = true + this.displayTerminal() + this.prevHeight = this.nearestRow(this.xterm.height()) + this.xterm.height(this.prevHeight) + this.emit('terminus:terminal-open') } else { - this.focus(); + this.focus() } - }); + }) - this.panel.show(); - this.xterm.height(0); - this.animating = true; - this.xterm.height(this.maximized ? this.maxHeight : this.prevHeight); + this.panel.show() + this.xterm.height(0) + this.animating = true + this.xterm.height(this.maximized ? this.maxHeight : this.prevHeight) } - hide() { + hide () { if (this.terminal) { - this.terminal.blur(); + this.terminal.blur() } - lastOpenedView = null; - this.statusIcon.deactivate(); + lastOpenedView = null + this.statusIcon.deactivate() this.onTransitionEnd(() => { - this.panel.hide(); + this.panel.hide() if (!lastOpenedView) { if (lastActiveElement) { - lastActiveElement.focus(); - lastActiveElement = null; + lastActiveElement.focus() + lastActiveElement = null } } - }); + }) - this.xterm.height(this.maximized ? this.maxHeight : this.prevHeight); - this.animating = true; - this.xterm.height(0); + this.xterm.height(this.maximized ? this.maxHeight : this.prevHeight) + this.animating = true + this.xterm.height(0) } - toggle() { - if (this.animating) { return; } + toggle () { + if (this.animating) { return } if (this.panel.isVisible()) { - this.hide(); + this.hide() } else { - this.open(); + this.open() } } - input(data) { - if (!this.ptyProcess.childProcess) { return; } + input (data) { + if (!this.ptyProcess.childProcess) { return } - this.terminal.stopScrolling(); - this.ptyProcess.send({event: "input", text: data}); + this.terminal.stopScrolling() + this.ptyProcess.send({ event: 'input', text: data }) } - resize(cols, rows) { - if (!this.ptyProcess.childProcess) { return; } + resize (cols, rows) { + if (!this.ptyProcess.childProcess) { return } - this.ptyProcess.send({event: "resize", rows, cols}); + this.ptyProcess.send({ event: 'resize', rows, cols }) } - pty() { + pty () { if (!this.opened) { return new Promise((resolve, reject) => { - this.emitter.on("terminus:terminal-open", resolve); - setTimeout(reject, 1000); + this.emitter.on('terminus:terminal-open', resolve) + setTimeout(reject, 1000) }).then(() => { - return this.ptyPromise(); - }); + return this.ptyPromise() + }) } - return this.ptyPromise(); + return this.ptyPromise() } - ptyPromise() { + ptyPromise () { return new Promise((resolve, reject) => { if (this.ptyProcess) { - this.ptyProcess.on("terminus:pty", resolve); - this.ptyProcess.send({event: "pty"}); - setTimeout(reject, 1000); + const timeout = setTimeout(() => reject(new Error('pty timeout')), 1000) + this.ptyProcess.on('terminus:pty', (pty) => { + clearTimeout(timeout) + resolve(pty) + }) + this.ptyProcess.send({ event: 'pty' }) } else { - reject(); + reject(new Error('no pty process')) } - }); - } - - applyStyle() { - const config = atom.config.get("terminus"); - - this.xterm.addClass(config.style.theme); - - this.subscriptions.add(atom.config.onDidChange("terminus.style.theme", event => { - this.xterm.removeClass(event.oldValue); - this.xterm.addClass(event.newValue); - })); - - if (config.toggles.cursorBlink) { this.xterm.addClass("cursor-blink"); } - - let editorFont = atom.config.get("editor.fontFamily"); - const defaultFont = "Menlo, Consolas, 'DejaVu Sans Mono', monospace"; - let overrideFont = config.style.fontFamily; - this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont; - - this.subscriptions.add(atom.config.onDidChange("editor.fontFamily", event => { - editorFont = event.newValue; - this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont; - })); - this.subscriptions.add(atom.config.onDidChange("terminus.style.fontFamily", event => { - overrideFont = event.newValue; - this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont; - })); - - let editorFontSize = atom.config.get("editor.fontSize"); - let overrideFontSize = config.style.fontSize; - this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px`; - - this.subscriptions.add(atom.config.onDidChange("editor.fontSize", event => { - editorFontSize = event.newValue; - this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px`; - this.resizeTerminalToView(); - })); - this.subscriptions.add(atom.config.onDidChange("terminus.style.fontSize", event => { - overrideFontSize = event.newValue; - this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px`; - this.resizeTerminalToView(); - })); + }) + } + + applyStyle () { + const config = atom.config.get('terminus') + + this.xterm.addClass(config.style.theme) + + this.subscriptions.add(atom.config.onDidChange('terminus.style.theme', event => { + this.xterm.removeClass(event.oldValue) + this.xterm.addClass(event.newValue) + })) + + if (config.toggles.cursorBlink) { this.xterm.addClass('cursor-blink') } + + let editorFont = atom.config.get('editor.fontFamily') + const defaultFont = "Menlo, Consolas, 'DejaVu Sans Mono', monospace" + let overrideFont = config.style.fontFamily + this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont + + this.subscriptions.add(atom.config.onDidChange('editor.fontFamily', event => { + editorFont = event.newValue + this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont + })) + this.subscriptions.add(atom.config.onDidChange('terminus.style.fontFamily', event => { + overrideFont = event.newValue + this.terminal.element.style.fontFamily = overrideFont || editorFont || defaultFont + })) + + let editorFontSize = atom.config.get('editor.fontSize') + let overrideFontSize = config.style.fontSize + this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px` + + this.subscriptions.add(atom.config.onDidChange('editor.fontSize', event => { + editorFontSize = event.newValue + this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px` + this.resizeTerminalToView() + })) + this.subscriptions.add(atom.config.onDidChange('terminus.style.fontSize', event => { + overrideFontSize = event.newValue + this.terminal.element.style.fontSize = `${overrideFontSize || editorFontSize}px` + this.resizeTerminalToView() + })) // first 8 colors i.e. 'dark' colors - this.terminal.colors[0] = config.ansiColors.normal.black.toHexString(); - this.terminal.colors[1] = config.ansiColors.normal.red.toHexString(); - this.terminal.colors[2] = config.ansiColors.normal.green.toHexString(); - this.terminal.colors[3] = config.ansiColors.normal.yellow.toHexString(); - this.terminal.colors[4] = config.ansiColors.normal.blue.toHexString(); - this.terminal.colors[5] = config.ansiColors.normal.magenta.toHexString(); - this.terminal.colors[6] = config.ansiColors.normal.cyan.toHexString(); - this.terminal.colors[7] = config.ansiColors.normal.white.toHexString(); + this.terminal.colors[0] = config.ansiColors.normal.black.toHexString() + this.terminal.colors[1] = config.ansiColors.normal.red.toHexString() + this.terminal.colors[2] = config.ansiColors.normal.green.toHexString() + this.terminal.colors[3] = config.ansiColors.normal.yellow.toHexString() + this.terminal.colors[4] = config.ansiColors.normal.blue.toHexString() + this.terminal.colors[5] = config.ansiColors.normal.magenta.toHexString() + this.terminal.colors[6] = config.ansiColors.normal.cyan.toHexString() + this.terminal.colors[7] = config.ansiColors.normal.white.toHexString() // 'bright' colors - this.terminal.colors[8] = config.ansiColors.zBright.brightBlack.toHexString(); - this.terminal.colors[9] = config.ansiColors.zBright.brightRed.toHexString(); - this.terminal.colors[10] = config.ansiColors.zBright.brightGreen.toHexString(); - this.terminal.colors[11] = config.ansiColors.zBright.brightYellow.toHexString(); - this.terminal.colors[12] = config.ansiColors.zBright.brightBlue.toHexString(); - this.terminal.colors[13] = config.ansiColors.zBright.brightMagenta.toHexString(); - this.terminal.colors[14] = config.ansiColors.zBright.brightCyan.toHexString(); - this.terminal.colors[15] = config.ansiColors.zBright.brightWhite.toHexString(); + this.terminal.colors[8] = config.ansiColors.zBright.brightBlack.toHexString() + this.terminal.colors[9] = config.ansiColors.zBright.brightRed.toHexString() + this.terminal.colors[10] = config.ansiColors.zBright.brightGreen.toHexString() + this.terminal.colors[11] = config.ansiColors.zBright.brightYellow.toHexString() + this.terminal.colors[12] = config.ansiColors.zBright.brightBlue.toHexString() + this.terminal.colors[13] = config.ansiColors.zBright.brightMagenta.toHexString() + this.terminal.colors[14] = config.ansiColors.zBright.brightCyan.toHexString() + this.terminal.colors[15] = config.ansiColors.zBright.brightWhite.toHexString() } - attachWindowEvents() { - $(window).on("resize", this.onWindowResize); + attachWindowEvents () { + $(window).on('resize', this.onWindowResize) } - detachWindowEvents() { - $(window).off("resize", this.onWindowResize); + detachWindowEvents () { + $(window).off('resize', this.onWindowResize) } - attachResizeEvents() { - this.panelDivider.on("mousedown", this.resizeStarted); + attachResizeEvents () { + this.panelDivider.on('mousedown', this.resizeStarted) } - detachResizeEvents() { - this.panelDivider.off("mousedown", this.resizeStarted); + detachResizeEvents () { + this.panelDivider.off('mousedown', this.resizeStarted) } - onWindowResize() { + onWindowResize () { if (!this.tabView) { - this.xterm.css("transition", ""); - const newHeight = $(window).height(); - const bottomPanel = $("atom-panel-container.bottom").first().get(0); - const overflow = bottomPanel.scrollHeight - bottomPanel.offsetHeight; + this.xterm.css('transition', '') + const newHeight = $(window).height() + const bottomPanel = $('atom-panel-container.bottom').first().get(0) + const overflow = bottomPanel.scrollHeight - bottomPanel.offsetHeight - const delta = newHeight - this.windowHeight; - this.windowHeight = newHeight; + const delta = newHeight - this.windowHeight + this.windowHeight = newHeight if (this.maximized) { - const clamped = Math.max(this.maxHeight + delta, this.rowHeight); + const clamped = Math.max(this.maxHeight + delta, this.rowHeight) - if (this.panel.isVisible()) { this.adjustHeight(clamped); } - this.maxHeight = clamped; + if (this.panel.isVisible()) { this.adjustHeight(clamped) } + this.maxHeight = clamped - this.prevHeight = Math.min(this.prevHeight, this.maxHeight); + this.prevHeight = Math.min(this.prevHeight, this.maxHeight) } else if (overflow > 0) { - const clamped = Math.max(this.nearestRow(this.prevHeight + delta), this.rowHeight); + const clamped = Math.max(this.nearestRow(this.prevHeight + delta), this.rowHeight) - if (this.panel.isVisible()) { this.adjustHeight(clamped); } - this.prevHeight = clamped; + if (this.panel.isVisible()) { this.adjustHeight(clamped) } + this.prevHeight = clamped } - this.xterm.css("transition", `height ${0.25 / this.animationSpeed}s linear`); + this.xterm.css('transition', `height ${0.25 / this.animationSpeed}s linear`) } - this.resizeTerminalToView(); + this.resizeTerminalToView() } - resizeStarted() { - if (this.maximized) { return; } - this.maxHeight = this.prevHeight + $(".item-views").height(); - $(document).on("mousemove", this.resizePanel); - $(document).on("mouseup", this.resizeStopped); - this.xterm.css("transition", ""); + resizeStarted () { + if (this.maximized) { return } + this.maxHeight = this.prevHeight + $('.item-views').height() + $(document).on('mousemove', this.resizePanel) + $(document).on('mouseup', this.resizeStopped) + this.xterm.css('transition', '') } - resizeStopped() { - $(document).off("mousemove", this.resizePanel); - $(document).off("mouseup", this.resizeStopped); - this.xterm.css("transition", `height ${0.25 / this.animationSpeed}s linear`); + resizeStopped () { + $(document).off('mousemove', this.resizePanel) + $(document).off('mouseup', this.resizeStopped) + this.xterm.css('transition', `height ${0.25 / this.animationSpeed}s linear`) } - nearestRow(value) { - const rows = Math.floor(value / this.rowHeight); - return rows * this.rowHeight; + nearestRow (value) { + const rows = Math.floor(value / this.rowHeight) + return rows * this.rowHeight } - resizePanel(event) { + resizePanel (event) { if (event.which !== 1) { - this.resizeStopped(); - return; + this.resizeStopped() + return } - const mouseY = $(window).height() - event.pageY; - const delta = mouseY - $("atom-panel-container.bottom").height() - $("atom-panel-container.footer").height(); - if (Math.abs(delta) <= ((this.rowHeight * 5) / 6)) { return; } + const mouseY = $(window).height() - event.pageY + const delta = mouseY - $('atom-panel-container.bottom').height() - $('atom-panel-container.footer').height() + if (Math.abs(delta) <= ((this.rowHeight * 5) / 6)) { return } - const clamped = Math.max(this.nearestRow(this.prevHeight + delta), this.rowHeight); - if (clamped > this.maxHeight) { return; } + const clamped = Math.max(this.nearestRow(this.prevHeight + delta), this.rowHeight) + if (clamped > this.maxHeight) { return } - this.xterm.height(clamped); - $(this.terminal.element).height(clamped); - this.prevHeight = clamped; + this.xterm.height(clamped) + $(this.terminal.element).height(clamped) + this.prevHeight = clamped - this.resizeTerminalToView(); + this.resizeTerminalToView() } - adjustHeight(height) { - this.xterm.height(height); - $(this.terminal.element).height(height); + adjustHeight (height) { + this.xterm.height(height) + $(this.terminal.element).height(height) } - copy() { - let text; + copy () { + let text if (this.terminal._selected) { // const textarea = this.terminal.getCopyTextarea(); text = this.terminal.grabText( this.terminal._selected.x1, this.terminal._selected.x2, - this.terminal._selected.y1, this.terminal._selected.y2); + this.terminal._selected.y1, this.terminal._selected.y2) } else { - const rawText = this.terminal.context.getSelection().toString(); - const rawLines = rawText.split(/\r?\n/g); - const lines = rawLines.map(line => line.replace(/\s/g, " ").trimRight()); - text = lines.join("\n"); + const rawText = this.terminal.context.getSelection().toString() + const rawLines = rawText.split(/\r?\n/g) + const lines = rawLines.map(line => line.replace(/\s/g, ' ').trimRight()) + text = lines.join('\n') } - atom.clipboard.write(text); + atom.clipboard.write(text) } - paste() { - this.input(atom.clipboard.read()); + paste () { + this.input(atom.clipboard.read()) } - insertSelection(customText) { - const editor = atom.workspace.getActiveTextEditor(); - if (!editor) { return; } - const runCommand = atom.config.get("terminus.toggles.runInsertedText"); - const selection = editor.getSelectedText(); - let selectionText = ""; + insertSelection (customText) { + const editor = atom.workspace.getActiveTextEditor() + if (!editor) { return } + const runCommand = atom.config.get('terminus.toggles.runInsertedText') + const selection = editor.getSelectedText() + let selectionText = '' if (selection) { - this.terminal.stopScrolling(); - selectionText = selection; + this.terminal.stopScrolling() + selectionText = selection } else { - const cursor = editor.getCursorBufferPosition(); + const cursor = editor.getCursorBufferPosition() if (cursor) { - const line = editor.lineTextForBufferRow(cursor.row); - this.terminal.stopScrolling(); - selectionText = line; - editor.moveDown(1); + const line = editor.lineTextForBufferRow(cursor.row) + this.terminal.stopScrolling() + selectionText = line + editor.moveDown(1) } } - this.input(`${customText. - replace(/\$L/, `${editor.getCursorBufferPosition().row + 1}`). - replace(/\$F/, path.basename(editor.buffer.getPath() ? editor.buffer.getPath() : ".")). - replace(/\$D/, path.dirname(editor.buffer.getPath() ? editor.buffer.getPath() : ".")). - replace(/\$S/, selectionText). - replace(/\$\$/, "$")}${runCommand ? os.EOL : ""}` - ); + this.input(`${customText + .replace(/\$L/, `${editor.getCursorBufferPosition().row + 1}`) + .replace(/\$F/, path.basename(editor.buffer.getPath() ? editor.buffer.getPath() : '.')) + .replace(/\$D/, path.dirname(editor.buffer.getPath() ? editor.buffer.getPath() : '.')) + .replace(/\$S/, selectionText) + .replace(/\$\$/, '$')}${runCommand ? os.EOL : ''}` + ) } - focus(fromWindowEvent) { - this.resizeTerminalToView(); - this.focusTerminal(fromWindowEvent); - this.statusBar.setActiveTerminalView(this); - super.focus(); + focus (fromWindowEvent) { + this.resizeTerminalToView() + this.focusTerminal(fromWindowEvent) + this.statusBar.setActiveTerminalView(this) + super.focus() } - blur() { - this.blurTerminal(); - super.blur(); + blur () { + this.blurTerminal() + super.blur() } - focusTerminal(fromWindowEvent) { - if (!this.terminal) { return; } + focusTerminal (fromWindowEvent) { + if (!this.terminal) { return } - lastActiveElement = $(document.activeElement); - if (fromWindowEvent && !(lastActiveElement.is("div.terminal") || lastActiveElement.parents("div.terminal").length)) { return; } + lastActiveElement = $(document.activeElement) + if (fromWindowEvent && !(lastActiveElement.is('div.terminal') || lastActiveElement.parents('div.terminal').length)) { return } - this.terminal.focus(); + this.terminal.focus() if (this.terminal._textarea) { - this.terminal._textarea.focus(); + this.terminal._textarea.focus() } else { - this.terminal.element.focus(); + this.terminal.element.focus() } } - blurTerminal() { - if (!this.terminal) { return; } + blurTerminal () { + if (!this.terminal) { return } - this.terminal.blur(); - this.terminal.element.blur(); + this.terminal.blur() + this.terminal.element.blur() if (lastActiveElement) { - lastActiveElement.focus(); + lastActiveElement.focus() } } - resizeTerminalToView() { - if (!this.panel.isVisible() && !this.tabView) { return; } + resizeTerminalToView () { + if (!this.panel.isVisible() && !this.tabView) { return } - const {cols, rows} = this.getDimensions(); - if ((cols <= 0) || (rows <= 0)) { return; } - if (!this.terminal) { return; } - if ((this.terminal.rows === rows) && (this.terminal.cols === cols)) { return; } + const { cols, rows } = this.getDimensions() + if ((cols <= 0) || (rows <= 0)) { return } + if (!this.terminal) { return } + if ((this.terminal.rows === rows) && (this.terminal.cols === cols)) { return } - this.resize(cols, rows); - this.terminal.resize(cols, rows); + this.resize(cols, rows) + this.terminal.resize(cols, rows) } - getDimensions() { - const fakeRow = $("
     
    "); + getDimensions () { + const fakeRow = $('
     
    ') - let cols, rows; + let cols, rows if (this.terminal) { - this.find(".terminal").append(fakeRow); - const fakeCol = fakeRow.children().first()[0].getBoundingClientRect(); - cols = Math.floor(this.xterm.width() / (fakeCol.width || 9)); - rows = Math.floor(this.xterm.height() / (fakeCol.height || 20)); - this.rowHeight = fakeCol.height; - fakeRow.remove(); + this.find('.terminal').append(fakeRow) + const fakeCol = fakeRow.children().first()[0].getBoundingClientRect() + cols = Math.floor(this.xterm.width() / (fakeCol.width || 9)) + rows = Math.floor(this.xterm.height() / (fakeCol.height || 20)) + this.rowHeight = fakeCol.height + fakeRow.remove() } else { - cols = Math.floor(this.xterm.width() / 9); - rows = Math.floor(this.xterm.height() / 20); + cols = Math.floor(this.xterm.width() / 9) + rows = Math.floor(this.xterm.height() / 20) } - return {cols, rows}; + return { cols, rows } } - onTransitionEnd(callback) { - this.xterm.one("webkitTransitionEnd", () => { - callback(); - this.animating = false; - }); + onTransitionEnd (callback) { + this.xterm.one('webkitTransitionEnd', () => { + callback() + this.animating = false + }) } - inputDialog() { - if (!InputDialog) { InputDialog = require("./input-dialog"); } - const dialog = new InputDialog(this); - dialog.attach(); + inputDialog () { + if (!InputDialog) { InputDialog = require('./input-dialog') } + const dialog = new InputDialog(this) + dialog.attach() } - rename() { - this.statusIcon.rename(); + rename () { + this.statusIcon.rename() } - toggleTabView() { + toggleTabView () { if (this.tabView) { - this.panel = atom.workspace.addBottomPanel({item: this, visible: false}); - this.attachResizeEvents(); - this.closeBtn.show(); - this.hideBtn.show(); - this.maximizeBtn.show(); - this.tabView = false; + this.panel = atom.workspace.addBottomPanel({ item: this, visible: false }) + this.attachResizeEvents() + this.closeBtn.show() + this.hideBtn.show() + this.maximizeBtn.show() + this.tabView = false } else { - this.panel.destroy(); - this.detachResizeEvents(); - this.closeBtn.hide(); - this.hideBtn.hide(); - this.maximizeBtn.hide(); - this.xterm.css("height", ""); - this.tabView = true; - if (lastOpenedView === this) { lastOpenedView = null; } + this.panel.destroy() + this.detachResizeEvents() + this.closeBtn.hide() + this.hideBtn.hide() + this.maximizeBtn.hide() + this.xterm.css('height', '') + this.tabView = true + if (lastOpenedView === this) { lastOpenedView = null } } } - getTitle() { - return this.statusIcon.getName() || "terminus"; + getTitle () { + return this.statusIcon.getName() || 'terminus' } - getIconName() { - return "terminal"; + getIconName () { + return 'terminal' } - getShell() { - return path.basename(this.shell); + getShell () { + return path.basename(this.shell) } - getShellPath() { - return this.shell; + getShellPath () { + return this.shell } - emit(event, data) { - return this.emitter.emit(event, data); + emit (event, data) { + return this.emitter.emit(event, data) } - onDidChangeTitle(callback) { - return this.emitter.on("did-change-title", callback); + onDidChangeTitle (callback) { + return this.emitter.on('did-change-title', callback) } - getPath() { - return this.getTerminalTitle(); + getPath () { + return this.getTerminalTitle() } - getTerminalTitle() { - return this.title || this.process; + getTerminalTitle () { + return this.title || this.process } - getTerminal() { - return this.terminal; + getTerminal () { + return this.terminal } - isAnimating() { - return this.animating; + isAnimating () { + return this.animating } } -TerminusView.prototype.animating = false; -TerminusView.prototype.id = ""; -TerminusView.prototype.maximized = false; -TerminusView.prototype.opened = false; -TerminusView.prototype.pwd = ""; -TerminusView.prototype.windowHeight = $(window).height(); -TerminusView.prototype.rowHeight = 20; -TerminusView.prototype.shell = ""; -TerminusView.prototype.tabView = false; - -module.exports = TerminusView; +TerminusView.prototype.animating = false +TerminusView.prototype.id = '' +TerminusView.prototype.maximized = false +TerminusView.prototype.opened = false +TerminusView.prototype.pwd = '' +TerminusView.prototype.windowHeight = $(window).height() +TerminusView.prototype.rowHeight = 20 +TerminusView.prototype.shell = '' +TerminusView.prototype.tabView = false + +module.exports = TerminusView diff --git a/spec/runner.js b/spec/runner.js index 55aa3dda..025041a6 100644 --- a/spec/runner.js +++ b/spec/runner.js @@ -1,4 +1,4 @@ -const { createRunner } = require("atom-jasmine3-test-runner"); +const { createRunner } = require('atom-jasmine3-test-runner') module.exports = createRunner({ random: true, @@ -6,6 +6,6 @@ module.exports = createRunner({ atom: true, attachToDom: true, ci: true, - customMatchers: true, + customMatchers: true } -}); +}) diff --git a/spec/terminus-spec.js b/spec/terminus-spec.js index 742ad23b..2b3cfd0d 100644 --- a/spec/terminus-spec.js +++ b/spec/terminus-spec.js @@ -1,26 +1,26 @@ -describe("Terminus", () => { - let workspaceElement, terminusPackage, activationPromise; +describe('Terminus', () => { + let workspaceElement, terminusPackage, activationPromise beforeEach(() => { - workspaceElement = atom.views.getView(atom.workspace); - atom.packages.activatePackage("status-bar"); - terminusPackage = atom.packages.loadPackage("terminus"); - activationPromise = atom.packages.activatePackage("terminus"); - }); + workspaceElement = atom.views.getView(atom.workspace) + atom.packages.activatePackage('status-bar') + terminusPackage = atom.packages.loadPackage('terminus') + activationPromise = atom.packages.activatePackage('terminus') + }) - describe("when the terminus:toggle event is triggered", () => { - it("creates status-bar element on activate", async () => { - expect(workspaceElement.querySelector(".terminus.status-bar")).not.toExist(); + describe('when the terminus:toggle event is triggered', () => { + it('creates status-bar element on activate', async () => { + expect(workspaceElement.querySelector('.terminus.status-bar')).not.toExist() - terminusPackage.activateNow(); - await activationPromise; + terminusPackage.activateNow() + await activationPromise - expect(workspaceElement.querySelector(".terminus.status-bar")).toExist(); - expect(workspaceElement.querySelector(".terminus.terminal-view")).not.toExist(); + expect(workspaceElement.querySelector('.terminus.status-bar')).toExist() + expect(workspaceElement.querySelector('.terminus.terminal-view')).not.toExist() - atom.commands.dispatch(workspaceElement, "terminus:toggle"); + atom.commands.dispatch(workspaceElement, 'terminus:toggle') - expect(workspaceElement.querySelector(".terminus.terminal-view")).toExist(); - }); - }); -}); + expect(workspaceElement.querySelector('.terminus.terminal-view')).toExist() + }) + }) +}) From 27613520cf7c25b5123a59548083ab69736598e3 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 19 Nov 2019 13:02:58 -0600 Subject: [PATCH 3/3] chore(lint): check lint before push --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ad878845..f3d1fee0 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,8 @@ }, "husky": { "hooks": { - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", + "pre-push": "npm run lint" } } }