Skip to content

Commit

Permalink
WIP: Align with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred-Barclay committed Sep 30, 2018
1 parent 5ae2468 commit d4190a1
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 32 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ Jerry Yu (https://github.com/yubaoquan)

Matt Pilott (https://github.com/matt3224)
* Fix copy-paste

Simas Čepaitis (https://github.com/geriBatai)
* Add City Lights theme
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.7.0-dev
* More unity with upstream
* Bump atom-space-pen-views to 2.2.0
* Add city lights theme (from @geriBatai)
* Add upstream API
* "clear" terminal option working

## 0.6.3
* Fix copy-paste, Issue #53 and PR #55 on PIO upstream (from @matt3224)
* Support for Atom 28 (Electron 2.0). See issue #77.
Expand Down
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Explain in README.md the differences between upstream and us
Split termination window to a new pane on left or right

Finish terminal colour settings

Improvements to lib/view.coffee
22 changes: 11 additions & 11 deletions lib/process.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ systemLanguage = do ->
return language

filteredEnvironment = do ->
env = _.omit process.env, 'ATOM_HOME', 'ELECTRON_RUN_AS_NODE', 'GOOGLE_API_KEY', 'NODE_ENV', 'NODE_PATH', 'userAgent', 'taskPath'
env = _.omit process.env, 'ATOM_HOME', 'ELECTRON_RUN_AS_NODE', 'GOOGLE_API_KEY', 'NODE_ENV', 'NODE_PATH', 'userAgent', 'taskPath'
env.LANG ?= systemLanguage
env.TERM_PROGRAM = 'termination'
return env

module.exports = (pwd, shell, args, options={}) ->
module.exports = (pwd, shell, args, env, options={}) ->
callback = @async()

if /zsh|bash/.test(shell) and args.indexOf('--login') == -1 and process.platform isnt 'win32'
args.unshift '--login'

ptyProcess = pty.fork shell, args,
cwd: pwd,
env: filteredEnvironment,
name: 'xterm-256color'

title = shell = path.basename shell
if shell
ptyProcess = pty.fork shell, args,
cwd: pwd,
env: _.extend(filteredEnvironment, env),
name: 'xterm-256color'
title = shell = path.basename shell
else
ptyProcess = pty.open()

emitTitle = _.throttle ->
emit('termination:title', ptyProcess.process)
Expand All @@ -47,3 +46,4 @@ module.exports = (pwd, shell, args, options={}) ->
switch event
when 'resize' then ptyProcess.resize(cols, rows)
when 'input' then ptyProcess.write(text)
when 'pty' then emit('termination:pty', ptyProcess.pty)
36 changes: 28 additions & 8 deletions lib/status-bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ StatusIcon = require './status-icon'

os = require 'os'
path = require 'path'
_ = require 'underscore'

module.exports =
class StatusBar extends View
Expand Down Expand Up @@ -54,6 +55,7 @@ class StatusBar extends View
return if @activeTerminal.isAnimating()
return @activeTerminal.toggle() if @activeTerminal == @terminalViews[3]
@activeTerminal.open() if @activeTerminalView(3)
'termination:clear': => @clear()
'termination:close': => @destroyActiveTerm()
'termination:close-all': => @closeAll()
'termination:rename': => @runInActiveView (i) -> i.rename()
Expand Down Expand Up @@ -121,7 +123,7 @@ class StatusBar extends View
handleFocus = =>
if @returnFocus
setTimeout =>
@returnFocus?.focus()
@returnFocus?.focus(true)
@returnFocus = null
, 100

Expand Down Expand Up @@ -170,6 +172,20 @@ class StatusBar extends View
pane.onDidDestroy -> tabBar.off 'drop', @onDropTabBar

createTerminalView: (autoRun) ->
shell = atom.config.get 'termination.core.shell'
shellArguments = atom.config.get 'termination.core.shellArguments'
args = shellArguments.split(/\s+/g).filter (arg) -> arg
shellEnv = atom.config.get 'termination.core.shellEnv'
env = {}
shellEnv.split(' ').forEach((element) =>
configVar = element.split('=')
envVar = {}
envVar[configVar[0]] = configVar[1]
env = _.extend(env, envVar)
)
@createEmptyTerminalView autoRun, shell, args, env

createEmptyTerminalView: (autoRun=[], shell = null, args = [], env= {}) ->
@registerPaneSubscription() unless @paneSubscription?

projectFolder = atom.project.getPaths()[0]
Expand All @@ -193,12 +209,8 @@ class StatusBar extends View
id = editorPath or projectFolder or home
id = filePath: id, folderPath: path.dirname(id)

shell = atom.config.get 'termination.core.shell'
shellArguments = atom.config.get 'termination.core.shellArguments'
args = shellArguments.split(/\s+/g).filter (arg) -> arg

statusIcon = new StatusIcon()
terminationView = new TerminationView(id, pwd, statusIcon, this, shell, args, autoRun)
terminationView = new TerminationView(id, pwd, statusIcon, this, shell, args, env, autoRun)
statusIcon.initialize(terminationView)

terminationView.attach()
Expand Down Expand Up @@ -239,7 +251,6 @@ class StatusBar extends View

if terminal = TerminationView.getFocusedTerminal()
@activeTerminal.blur()

else
@activeTerminal.focusTerminal()

Expand Down Expand Up @@ -267,6 +278,11 @@ class StatusBar extends View
return callback(view)
return null

runNewTerminal: () ->
@activeTerminal = @createEmptyTerminalView()
@activeTerminal.toggle()
return @activeTerminal

runCommandInNewTerminal: (commands) ->
@activeTerminal = @createTerminalView(commands)
@activeTerminal.toggle()
Expand Down Expand Up @@ -337,6 +353,10 @@ class StatusBar extends View
@activeTerminal = @terminalViews[0]
@activeTerminal.toggle()

clear: ->
@destroyActiveTerm()
@newTerminalView()

setStatusColor: (event) ->
color = event.type.match(/\w+$/)[0]
color = atom.config.get("termination.iconColors.#{color}").toRGBAString()
Expand Down Expand Up @@ -424,7 +444,7 @@ class StatusBar extends View
@statusContainer.children().eq(fromIndex).detach()
view.statusIcon.removeTooltip()

pane.addItem view, { index: pane.getItems().length }
pane.addItem view, pane.getItems().length
pane.activateItem view

view.focus()
Expand Down
24 changes: 23 additions & 1 deletion lib/termination.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ module.exports =
@statusBarTile?.destroy()
@statusBarTile = null

provideTerminationTerminal: ->
updateProcessEnv: (variables) ->
for name, value of variables
process.env[name] = value
run: (commands) =>
@statusBarTile.runCommandInNewTerminal commands
getTerminalViews: () =>
@statusBarTile.terminalViews
open: () =>
@statusBarTile.runNewTerminal()

provideRunInTerminal: ->
run: (commands) =>
@statusBarTile.runCommandInNewTerminal commands
Expand Down Expand Up @@ -42,6 +53,11 @@ module.exports =
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'
default: true
cloneTerminalPlus:
title: 'Clone Terminal-Plus'
description: 'Should there be a dedicated bottom panel for termination?
Expand Down Expand Up @@ -91,6 +107,11 @@ module.exports =
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: ''
workingDirectory:
title: 'Working Directory'
description: 'Which directory should be the present working directory
Expand Down Expand Up @@ -152,7 +173,8 @@ module.exports =
'one-dark',
'one-light',
'bliss',
'gruvbox'
'gruvbox',
'city-lights'
]
iconColors:
type: 'object'
Expand Down
48 changes: 38 additions & 10 deletions lib/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TerminationView extends View
@getFocusedTerminal: ->
return Terminal.Terminal.focus

initialize: (@id, @pwd, @statusIcon, @statusBar, @shell, @args=[], @autoRun=[]) ->
initialize: (@id, @pwd, @statusIcon, @statusBar, @shell, @args=[], @env={}, @autoRun=[]) ->
@subscriptions = new CompositeDisposable
@emitter = new Emitter

Expand Down Expand Up @@ -71,7 +71,12 @@ class TerminationView extends View
@xterm.on 'mouseup', (event) =>
if event.which != 3
text = window.getSelection().toString()
atom.clipboard.write(text) if atom.config.get('termination.toggles.selectToCopy') and text
if atom.config.get('termination.toggles.selectToCopy') and text
rawLines = text.split(/\r?\n/g)
lines = rawLines.map (line) ->
line.replace(/\s/g, " ").trimRight()
text = lines.join("\n")
atom.clipboard.write(text)
unless text
@focus()
@xterm.on 'dragenter', override
Expand All @@ -82,6 +87,9 @@ class TerminationView extends View
@subscriptions.add dispose: =>
@off 'focus', @focus

if /zsh|bash/.test(@shell) and @args.indexOf('--login') == -1 and Pty.platform isnt 'win32' and atom.config.get('termination.toggles.loginShell')
@args.unshift '--login'

attach: ->
return if @panel?
@panel = atom.workspace.addBottomPanel(item: this, visible: false)
Expand All @@ -107,7 +115,7 @@ class TerminationView extends View
@input "#{file.path} "

forkPtyProcess: ->
Task.once Pty, path.resolve(@pwd), @shell, @args, =>
Task.once Pty, path.resolve(@pwd), @shell, @args, @env, =>
@input = ->
@resize = ->

Expand Down Expand Up @@ -224,6 +232,7 @@ class TerminationView extends View
@displayTerminal()
@prevHeight = @nearestRow(@xterm.height())
@xterm.height(@prevHeight)
@emit "termination:terminal-open"
else
@focus()

Expand Down Expand Up @@ -267,6 +276,28 @@ class TerminationView extends View

@ptyProcess.send {event: 'resize', rows, cols}

pty: () ->
if not @opened
wait = new Promise (resolve, reject) =>
@emitter.on "platformio-ide-terminal:terminal-open", () =>
resolve()
setTimeout reject, 1000

wait.then () =>
@ptyPromise()
else
@ptyPromise()

ptyPromise: () ->
new Promise (resolve, reject) =>
if @ptyProcess?
@ptyProcess.on "platformio-ide-terminal:pty", (pty) =>
resolve(pty)
@ptyProcess.send {event: 'pty'}
setTimeout reject, 1000
else
reject()

applyStyle: ->
config = atom.config.get 'termination'

Expand Down Expand Up @@ -414,10 +445,6 @@ class TerminationView extends View
paste: ->
@input atom.clipboard.read()

clear: ->
@terminal.destroy()
@displayTerminal()

copyAllToNewFile: ->
text = @terminal.lines.map (line) ->
line.map (cols) -> cols[1]
Expand Down Expand Up @@ -446,20 +473,21 @@ class TerminationView extends View
replace(/\$S/, selectionText).
replace(/\$\$/, '$')}#{if runCommand then os.EOL else ''}"

focus: =>
focus: (fromWindowEvent) =>
@resizeTerminalToView()
@focusTerminal()
@focusTerminal(fromWindowEvent)
@statusBar.setActiveTerminalView(this)
super()

blur: =>
@blurTerminal()
super()

focusTerminal: =>
focusTerminal: (fromWindowEvent) =>
return unless @terminal

lastActiveElement = $(document.activeElement)
return if fromWindowEvent and not (lastActiveElement.is('div.terminal') or lastActiveElement.parents('div.terminal').length)

@terminal.focus()
if @terminal._textarea
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@
"bugs": "https://github.com/Fred-Barclay/Termination/issues",
"license": "MIT",
"engines": {
"atom": ">=1.19.0"
"atom": ">=1.19.0 <2.0.0"
},
"dependencies": {
"atom-space-pen-views": "^2.1.0",
"atom-space-pen-views": "^2.2.0",
"pty.js": "https://github.com/platformio/pty.js/tarball/prebuilt",
"term.js": "https://github.com/jeremyramin/term.js/tarball/master",
"underscore": "^1.8.3"
},
"activationHooks": [
"core:loaded-shell-environment"
],
"consumedServices": {
"status-bar": {
"versions": {
Expand All @@ -57,6 +60,12 @@
}
},
"providedServices": {
"platformioIDETerminal": {
"description": "PlatformIO IDE Terminal API",
"versions": {
"1.1.0": "providePlatformIOIDETerminal"
}
},
"runInTerminal": {
"description": "Allow to run commands in terminal.",
"versions": {
Expand Down
1 change: 1 addition & 0 deletions styles/themes.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
@import 'themes/one-light';
@import 'themes/bliss';
@import 'themes/gruvbox';
@import 'themes/city-lights';
}
11 changes: 11 additions & 0 deletions styles/themes/city-lights.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.city-lights {
background-color: #181d23;
color: #666d81;
::selection {
background-color: #2a2f38;
color: #b7c5d3;
}
.terminal-cursor {
background-color: #528BFF;
}
}

0 comments on commit d4190a1

Please sign in to comment.