This repository has been archived by the owner on Mar 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: render terminals in the bottom dock #14
Draft
akonwi
wants to merge
2
commits into
bus-stop:master
Choose a base branch
from
akonwi:docks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const isString = x => typeof x === 'string' | ||
|
||
// visibility for items in bottom dock | ||
module.exports.isVisible = function (itemOrUri) { | ||
const uri = isString(itemOrUri) ? itemOrUri : itemOrUri.getURI() | ||
|
||
const dock = atom.workspace.getBottomDock() | ||
if (!dock.isVisible()) return false | ||
|
||
const activeItem = dock.getActivePaneItem() | ||
if (!activeItem) return false | ||
|
||
return activeItem.getURI && activeItem.getURI() === uri | ||
} | ||
|
||
module.exports.isUseDockEnabled = () => atom.config.get('terminus.toggles.useDock') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ const { $, View } = require('atom-space-pen-views') | |
|
||
const Pty = require.resolve('./process') | ||
const Terminal = require('term.js') | ||
const { isUseDockEnabled, isVisible } = require('./utils') | ||
let InputDialog = null | ||
|
||
const path = require('path') | ||
|
@@ -11,6 +12,8 @@ const os = require('os') | |
let lastOpenedView = null | ||
let lastActiveElement = null | ||
|
||
let nextId = 0 | ||
|
||
class TerminusView extends View { | ||
static content () { | ||
this.div({ class: 'terminus terminal-view', outlet: 'terminusView' }, () => { | ||
|
@@ -20,11 +23,13 @@ class TerminusView extends View { | |
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' }) | ||
}) | ||
if (!isUseDockEnabled()) { | ||
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' }) | ||
|
@@ -35,7 +40,17 @@ class TerminusView extends View { | |
return Terminal.Terminal.focus | ||
} | ||
|
||
getURI () { return `atom://terminus/${this.viewId}` } | ||
|
||
getDefaultLocation () { return 'bottom' } | ||
|
||
getAllowedLocations () { return ['bottom'] } | ||
|
||
isPermanentDockItem () { return false } | ||
|
||
initialize (id, pwd, statusIcon, statusBar, shell, args = [], env = {}, autoRun = []) { | ||
this.shouldUseDock = isUseDockEnabled() | ||
if (this.shouldUseDock) { this.viewId = nextId++ } | ||
this.id = id | ||
this.pwd = pwd | ||
this.statusIcon = statusIcon | ||
|
@@ -56,24 +71,28 @@ class TerminusView extends View { | |
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' }) | ||
if (!this.shouldUseDock) { | ||
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) | ||
if (!this.shouldUseDock) { this.xterm.height(0) } | ||
|
||
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)) | ||
if (!this.shouldUseDock) { | ||
this.updateToolbarVisibility() | ||
this.subscriptions.add(atom.config.onDidChange('terminus.toggles.showToolbar', this.updateToolbarVisibility)) | ||
} | ||
|
||
const override = (event) => { | ||
if (event.originalEvent.dataTransfer.getData('terminus') === 'true') { return } | ||
|
@@ -112,8 +131,12 @@ class TerminusView extends View { | |
} | ||
|
||
attach () { | ||
if (this.panel) { return } | ||
this.panel = atom.workspace.addBottomPanel({ item: this, visible: false }) | ||
if (this.shouldUseDock) { | ||
atom.workspace.open(this) | ||
} else { | ||
if (this.panel) { return } | ||
this.panel = atom.workspace.addBottomPanel({ item: this, visible: false }) | ||
} | ||
} | ||
|
||
setAnimationSpeed () { | ||
|
@@ -199,10 +222,11 @@ class TerminusView extends View { | |
|
||
this.ptyProcess.on('terminus:title', title => { | ||
this.process = title | ||
this.emit('did-change-title') | ||
}) | ||
this.terminal.on('title', title => { | ||
this.title = title | ||
}) | ||
// this.terminal.on('title', title => { | ||
// this.title = title | ||
// }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll be interested to check these title changes out. =) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good NewsI These changes you made into title actually fix #12 feel fee to submit them separately along with rename changes =) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually only fixed Linux side, Windows now doesnt even show any other name but xterm-256color |
||
|
||
this.terminal.once('open', () => { | ||
this.applyStyle() | ||
|
@@ -215,18 +239,24 @@ class TerminusView extends View { | |
}) | ||
} | ||
|
||
onDidDestroy (callback) { | ||
return this.emitter.on('did-destroy', callback) | ||
} | ||
|
||
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()) | ||
} else { | ||
this.panel.destroy() | ||
if (!this.shouldUseDock) { | ||
if (this.panel.isVisible()) { | ||
this.hide() | ||
this.onTransitionEnd(() => this.panel.destroy()) | ||
} else { | ||
this.panel.destroy() | ||
} | ||
} | ||
|
||
if (this.statusIcon && this.statusIcon.parentNode) { | ||
|
@@ -239,6 +269,9 @@ class TerminusView extends View { | |
if (this.terminal) { | ||
this.terminal.destroy() | ||
} | ||
|
||
this.emit('did-destroy') | ||
this.emitter.dispose() | ||
} | ||
|
||
maximize () { | ||
|
@@ -269,6 +302,8 @@ class TerminusView extends View { | |
lastActiveElement = $(document.activeElement) | ||
} | ||
|
||
if (this.shouldUseDock) { return this.openInDock() } | ||
|
||
if (lastOpenedView && (lastOpenedView !== this)) { | ||
if (lastOpenedView.maximized) { | ||
this.subscriptions.remove(this.maximizeBtn.tooltip) | ||
|
@@ -306,7 +341,21 @@ class TerminusView extends View { | |
this.xterm.height(this.maximized ? this.maxHeight : this.prevHeight) | ||
} | ||
|
||
openInDock () { | ||
this.statusBar.setActiveTerminalView(this) | ||
this.statusIcon.activate() | ||
atom.workspace.open(this, { activatePane: true }).then(() => { | ||
if (!this.opened) { | ||
this.opened = true | ||
this.displayTerminal() | ||
this.xterm.height('100%') | ||
this.emit('terminus:terminal-open') | ||
} else this.focus() | ||
}) | ||
} | ||
|
||
hide () { | ||
if (this.shouldUseDock) return this.hideInDock() | ||
if (this.terminal) { | ||
this.terminal.blur() | ||
} | ||
|
@@ -328,7 +377,15 @@ class TerminusView extends View { | |
this.xterm.height(0) | ||
} | ||
|
||
hideInDock () { | ||
this.terminal && this.terminal.blur() | ||
this.statusIcon.deactivate() | ||
atom.workspace.hide(this) | ||
} | ||
|
||
toggle () { | ||
if (this.shouldUseDock) return this.toggleInDock() | ||
|
||
if (this.animating) { return } | ||
|
||
if (this.panel.isVisible()) { | ||
|
@@ -338,6 +395,10 @@ class TerminusView extends View { | |
} | ||
} | ||
|
||
toggleInDock () { | ||
if (isVisible(this)) { this.hide() } else { this.open() } | ||
} | ||
|
||
input (data) { | ||
if (!this.ptyProcess.childProcess) { return } | ||
|
||
|
@@ -614,6 +675,8 @@ class TerminusView extends View { | |
} | ||
|
||
resizeTerminalToView () { | ||
if (this.shouldUseDock) return this.resizeInDock() | ||
|
||
if (!this.panel.isVisible() && !this.tabView) { return } | ||
|
||
const { cols, rows } = this.getDimensions() | ||
|
@@ -625,6 +688,19 @@ class TerminusView extends View { | |
this.terminal.resize(cols, rows) | ||
} | ||
|
||
resizeInDock () { | ||
if (!isVisible(this)) return | ||
|
||
const { cols, rows } = this.getDimensions() | ||
if (cols > 0 && rows > 0) { | ||
if (this.terminal) { | ||
if (this.terminal.rows === rows && this.terminal.cols === cols) return | ||
this.resize(cols, rows) | ||
this.terminal.resize(cols, rows) | ||
} | ||
} | ||
} | ||
|
||
getDimensions () { | ||
const fakeRow = $('<div><span> </span></div>') | ||
|
||
|
@@ -657,8 +733,9 @@ class TerminusView extends View { | |
dialog.attach() | ||
} | ||
|
||
rename () { | ||
this.statusIcon.rename() | ||
didRename (title) { | ||
this.title = title | ||
this.emit('did-change-title') | ||
} | ||
|
||
toggleTabView () { | ||
|
@@ -682,6 +759,7 @@ class TerminusView extends View { | |
} | ||
|
||
getTitle () { | ||
if (this.shouldUseDock) { return this.getTerminalTitle() } | ||
return this.statusIcon.getName() || 'terminus' | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, does this indeed also terminate the associated ptyProcess?