forked from jeremyramin/terminal-plus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still buggy, but functional.
- Loading branch information
0 parents
commit e9dfeb4
Showing
15 changed files
with
1,079 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
npm-debug.log | ||
node_modules |
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,3 @@ | ||
## 0.0.0 - First Release | ||
* Every feature added | ||
* Every bug fixed |
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,20 @@ | ||
Copyright (c) 2015 <Your name here> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,5 @@ | ||
# terminal-plus package | ||
|
||
A short description of your package. | ||
|
||
![A screenshot of your package](https://f.cloud.github.com/assets/69169/2290250/c35d867a-a017-11e3-86be-cd7c5bf3ff9b.gif) |
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,23 @@ | ||
|
||
'.platform-darwin atom-workspace': | ||
'cmd-shift-t': 'terminal-plus:new' | ||
'cmd-shift-j': 'terminal-plus:prev' | ||
'cmd-shift-k': 'terminal-plus:next' | ||
'cmd-shift-x': 'terminal-plus:destroy' | ||
'ctrl-`': 'terminal-plus:toggle' | ||
|
||
'.platform-linux atom-workspace, .platform-win32 atom-workspace': | ||
'alt-shift-t': 'terminal-plus:new' | ||
'alt-shift-j': 'terminal-plus:prev' | ||
'alt-shift-k': 'terminal-plus:next' | ||
'alt-shift-x': 'terminal-plus:destroy' | ||
'ctrl-`': 'terminal-plus:toggle' | ||
|
||
'.terminal-plus-view .terminal': | ||
'escape': 'terminal-plus:toggle' | ||
'cmd-c': 'terminal-plus:copy' | ||
'ctrl-c': 'terminal-plus:copy' | ||
'ctrl-insert': 'terminal-plus:copy' | ||
'cmd-v': 'terminal-plus:paste' | ||
'ctrl-v': 'terminal-plus:paste' | ||
'shift-insert': 'terminal-plus:paste' |
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,127 @@ | ||
### | ||
terminal-plus | ||
Copyright by isis97 | ||
MIT licensed | ||
The very basic class, which handles the configuration files, loads up commands and | ||
answers all the commands requests generated by terminal instance. | ||
### | ||
|
||
{resolve, dirname, extname} = require 'path' | ||
fs = require 'fs' | ||
|
||
class TerminalPlusCore | ||
|
||
state: | ||
config: {} | ||
statePath: null | ||
opened: false | ||
customCommands: {} | ||
defaultCommands: | ||
"hello_world": { | ||
"description": "Prints the hello world message to the terminal output." | ||
"command": [ | ||
"echo Hello world :D", | ||
"echo This is", | ||
"echo example usage", | ||
"echo of the console" | ||
] | ||
} | ||
|
||
defaultCommandsFile: () -> | ||
return initialContent = { | ||
'_comment': 'Package terminal-plus: This terminal-commands.json file was automatically generated by atom-terminal-package. It contains all useful config data.' | ||
commands: @state.defaultCommands | ||
actions: [] | ||
toolbar: [ | ||
["clear", "clear", "Clears the console output."], | ||
["info", "info", "Prints the terminal welcome message."], | ||
["all available commands", "memdump", "Displays all available builtin commands. (all commands except native)"] | ||
] | ||
rules: { | ||
"\\b[A-Z][A-Z]+\\b": { | ||
'match': { | ||
'flags': ['g'] | ||
} | ||
'css': { | ||
'color':'gray' | ||
} | ||
} | ||
'(error|err):? (.*)': { | ||
'match': { | ||
'matchLine': true | ||
'replace': '%(label:error:text:Error) %(0)' | ||
} | ||
'css': { | ||
'color': 'red' | ||
'font-weight': 'bold' | ||
} | ||
} | ||
'(warning|warn|alert):? (.*)': { | ||
'match': { | ||
'matchLine': true | ||
'replace': '%(label:warning:text:Warning) %(0)' | ||
} | ||
'css': { | ||
'color': 'yellow' | ||
} | ||
} | ||
'(note|info):? (.*)': { | ||
'match': { | ||
'matchLine': true | ||
'replace': '%(label:info:text:Info) %(0)' | ||
} | ||
'css': { | ||
|
||
} | ||
} | ||
'(debug|dbg):? (.*)': { | ||
'match': { | ||
'matchLine': true | ||
'replace': '%(label:default:text:Debug) %(0)' | ||
} | ||
'css': { | ||
'color': 'gray' | ||
} | ||
} | ||
} | ||
} | ||
|
||
createDefaultCommandsFile: () -> | ||
if atom.config.get('terminal-plus.enableUserCommands') | ||
try | ||
content = JSON.stringify @defaultCommandsFile(), null, '\t' | ||
fs.writeFileSync @state.statePath, content | ||
catch e | ||
console.log 'atp-core cannot create default terminal commands JSON file', e.message | ||
|
||
reload: () -> | ||
@state.opened = false | ||
@init() | ||
|
||
init: () -> | ||
if not @state.opened | ||
@state.opened = true | ||
@state.statePath = dirname(atom.config.getUserConfigPath()) + '/terminal-commands.json' | ||
try | ||
@state.config = JSON.parse fs.readFileSync @state.statePath | ||
@state.customCommands = @state.config.commands | ||
catch e | ||
atom.notifications.addWarning 'Terminal-Plus: Failed to load terminal configuration file', {detail:e.message} | ||
@state.config = @defaultCommandsFile() | ||
@state.customCommands = @state.defaultCommands | ||
return this | ||
|
||
jsonCssToInlineStyle: (obj) -> | ||
if obj instanceof String | ||
return obj | ||
ret = '' | ||
for key, value of obj | ||
if key? and value? | ||
ret += key + ':' + value + ';' | ||
return ret | ||
|
||
getConfig: () -> | ||
return @state.config | ||
|
||
module.exports = new TerminalPlusCore() |
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,139 @@ | ||
{$, View} = require 'atom-space-pen-views' | ||
TerminalPlusView = require './view' | ||
|
||
module.exports = | ||
class TerminalPlusPanel extends View | ||
@content: -> | ||
@div class: 'terminal-plus-panel inline-block', => | ||
@span outlet: 'termStatusContainer', => | ||
@span click: 'newTermClick', class: "icon icon-plus" | ||
|
||
commandViews: [] | ||
activeIndex: 0 | ||
initialize: (serializeState) -> | ||
|
||
getSelectedText = () -> | ||
text = '' | ||
if window.getSelection | ||
text = window.getSelection().toString() | ||
else if document.selection and document.selection.type != "Control" | ||
text = document.selection.createRange().text | ||
return text | ||
|
||
atom.commands.add 'atom-workspace', | ||
'terminal-plus:new': => @newTermClick() | ||
'terminal-plus:toggle': => @toggle() | ||
'terminal-plus:next': => @activeNextCommandView() | ||
'terminal-plus:prev': => @activePrevCommandView() | ||
'terminal-plus:hide': => @runInCurrentView (i) -> i.close() | ||
'terminal-plus:destroy': => @runInCurrentView (i) -> i.destroy() | ||
'terminal-plus:reload-config': => @runInCurrentView (i) -> | ||
i.clear() | ||
i.reloadSettings() | ||
i.clear() | ||
'terminal-plus:open-config': => @runInCurrentView (i) -> | ||
i.showSettings() | ||
|
||
@createCommandView() | ||
@attach() | ||
|
||
getColors: -> | ||
{ | ||
normalBlack, normalRed, normalGreen, normalYellow | ||
normalBlue, normalPurple, normalCyan, normalWhite | ||
brightBlack, brightRed, brightGreen, brightYellow | ||
brightBlue, brightPurple, brightCyan, brightWhite | ||
background, foreground | ||
} = (atom.config.getAll 'terminal-plus.colors')[0].value | ||
[ | ||
normalBlack, normalRed, normalGreen, normalYellow | ||
normalBlue, normalPurple, normalCyan, normalWhite | ||
brightBlack, brightRed, brightGreen, brightYellow | ||
brightBlue, brightPurple, brightCyan, brightWhite | ||
background, foreground | ||
] | ||
|
||
createCommandView: -> | ||
termStatus = $('<span class="icon icon-terminal"></span>') | ||
|
||
options = | ||
runCommand : atom.config.get 'terminal-plus.autoRunCommand' | ||
shellOverride : atom.config.get 'terminal-plus.shellOverride' | ||
shellArguments: atom.config.get 'terminal-plus.shellArguments' | ||
titleTemplate : atom.config.get 'terminal-plus.titleTemplate' | ||
cursorBlink : atom.config.get 'terminal-plus.cursorBlink' | ||
fontFamily : atom.config.get 'terminal-plus.fontFamily' | ||
fontSize : atom.config.get 'terminal-plus.fontSize' | ||
colors : @getColors() | ||
|
||
terminalPlusView = new TerminalPlusView(options) | ||
terminalPlusView.statusIcon = termStatus | ||
terminalPlusView.statusView = this | ||
@commandViews.push terminalPlusView | ||
termStatus.click () => | ||
terminalPlusView.toggle() | ||
@termStatusContainer.append termStatus | ||
return terminalPlusView | ||
|
||
activeNextCommandView: -> | ||
@activeCommandView @activeIndex + 1 | ||
|
||
activePrevCommandView: -> | ||
@activeCommandView @activeIndex - 1 | ||
|
||
activeCommandView: (index) -> | ||
if index >= @commandViews.length | ||
index = 0 | ||
if index < 0 | ||
index = @commandViews.length - 1 | ||
@updateStatusBar @commandViews[index] | ||
@commandViews[index] and @commandViews[index].open() | ||
|
||
getActiveCommandView: () -> | ||
return @commandViews[@activeIndex] | ||
|
||
runInCurrentView: (call) -> | ||
v = @getForcedActiveCommandView() | ||
if v? | ||
return call(v) | ||
return null | ||
|
||
getForcedActiveCommandView: () -> | ||
if @getActiveCommandView() != null && @getActiveCommandView() != undefined | ||
return @getActiveCommandView() | ||
ret = @activeCommandView(0) | ||
@toggle() | ||
return ret | ||
|
||
setActiveCommandView: (commandView) -> | ||
@activeIndex = @commandViews.indexOf commandView | ||
|
||
removeCommandView: (commandView) -> | ||
index = @commandViews.indexOf commandView | ||
index >=0 and @commandViews.splice index, 1 | ||
|
||
newTermClick: -> | ||
@createCommandView().toggle() | ||
|
||
attach: () -> | ||
# console.log 'panel attached!' | ||
atom.workspace.addBottomPanel(item: this, priority: 100) | ||
|
||
destroyActiveTerm: -> | ||
@commandViews[@activeIndex]?.destroy() | ||
|
||
closeAll: -> | ||
for index in [@commandViews.length .. 0] | ||
o = @commandViews[index] | ||
if o? | ||
o.close() | ||
|
||
# Tear down any state and detach | ||
destroy: -> | ||
for index in [@commandViews.length .. 0] | ||
@removeCommandView @commandViews[index] | ||
@detach() | ||
|
||
toggle: -> | ||
@createCommandView() unless @commandViews[@activeIndex]? | ||
@commandViews[@activeIndex].toggle() |
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,36 @@ | ||
pty = require 'pty.js' | ||
{execSync} = require 'child_process' | ||
|
||
module.exports = (ptyCwd, sh, args) -> | ||
callback = @async() | ||
if sh | ||
shell = sh | ||
else | ||
if process.platform is 'win32' | ||
path = require 'path' | ||
shell = path.resolve(process.env.SystemRoot, 'WindowsPowerShell', 'v1.0', 'powershell.exe') | ||
else | ||
shell = process.env.SHELL | ||
|
||
cols = 80 | ||
rows = 30 | ||
|
||
cmd = 'test -e /etc/profile && source /etc/profile;test -e ~/.profile && source ~/.profile; node -pe "JSON.stringify(process.env)"' | ||
env = JSON.parse execSync cmd | ||
|
||
ptyProcess = pty.fork shell, args, | ||
name: 'xterm-256color' | ||
cols: cols | ||
rows: rows | ||
cwd: ptyCwd | ||
env: env | ||
|
||
ptyProcess.on 'data', (data) -> emit('terminal-plus:data', data) | ||
ptyProcess.on 'exit', -> | ||
emit('terminal-plus:exit') | ||
callback() | ||
|
||
process.on 'message', ({event, cols, rows, text}={}) -> | ||
switch event | ||
when 'resize' then ptyProcess.resize(cols, rows) | ||
when 'input' then ptyProcess.write(text) |
Oops, something went wrong.