-
-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(terminal) add optional --terminal support
- Loading branch information
1 parent
9c80c0f
commit db2a58c
Showing
14 changed files
with
266 additions
and
19 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
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,129 @@ | ||
'use strict'; | ||
|
||
/* global CloudCmd, gritty */ | ||
|
||
const exec = require('execon'); | ||
const load = require('../dom/load'); | ||
const DOM = require('../dom'); | ||
const Images = require('../dom/images'); | ||
const {Dialog} = DOM; | ||
|
||
const TITLE = 'Terminal'; | ||
|
||
CloudCmd.Terminal = TerminalProto; | ||
|
||
const {Key} = CloudCmd; | ||
|
||
let Element; | ||
let Loaded; | ||
let Terminal; | ||
|
||
const {config} = CloudCmd; | ||
|
||
function TerminalProto() { | ||
if (!config('terminal')) | ||
return; | ||
|
||
Images.show.load('top'); | ||
|
||
exec.series([ | ||
CloudCmd.View, | ||
loadAll, | ||
create, | ||
show, | ||
]); | ||
|
||
Element = load({ | ||
name: 'div', | ||
style: 'height: 99%', | ||
className : 'terminal', | ||
}); | ||
|
||
return module.exports; | ||
} | ||
|
||
module.exports.show = show; | ||
|
||
module.exports.hide = hide; | ||
|
||
function hide () { | ||
CloudCmd.View.hide(); | ||
} | ||
|
||
function getPrefix() { | ||
return CloudCmd.PREFIX + '/gritty'; | ||
} | ||
|
||
function getEnv() { | ||
return { | ||
ACTIVE_DIR: DOM.getCurrentDirPath, | ||
PASSIVE_DIR: DOM.getNotCurrentDirPath, | ||
CURRENT_NAME: DOM.getCurrentName, | ||
CURRENT_PATH: DOM.getCurrentPath | ||
}; | ||
} | ||
|
||
function create(callback) { | ||
const options = { | ||
env: getEnv(), | ||
prefix: getPrefix(), | ||
socketPath: CloudCmd.PREFIX, | ||
}; | ||
|
||
const {socket, terminal} = gritty(Element, options); | ||
|
||
terminal.focus(); | ||
|
||
Terminal = terminal; | ||
|
||
terminal.on('key', (char, {keyCode, shiftKey}) => { | ||
if (shiftKey && keyCode === Key.ESC) { | ||
hide(); | ||
} | ||
}); | ||
|
||
socket.on('connect', exec.with(authCheck, socket)); | ||
|
||
exec(callback); | ||
} | ||
|
||
function authCheck(spawn) { | ||
if (!config('auth')) | ||
return; | ||
|
||
spawn.emit('auth', config('username'), config('password')); | ||
|
||
spawn.on('reject', () => { | ||
Dialog.alert(TITLE, 'Wrong credentials!'); | ||
}); | ||
} | ||
|
||
function show(callback) { | ||
if (!Loaded) | ||
return; | ||
|
||
CloudCmd.View.show(Element, { | ||
afterShow: () => { | ||
if (Terminal) { | ||
Terminal.fit(); // lines corrupt without | ||
Terminal.focus(); | ||
} | ||
|
||
exec(callback); | ||
} | ||
}); | ||
} | ||
|
||
function loadAll(callback) { | ||
const prefix = getPrefix(); | ||
const url = prefix + '/gritty.js'; | ||
|
||
DOM.load.js(url, (error) => { | ||
if (error) | ||
return Dialog.alert(TITLE, error.message); | ||
|
||
Loaded = true; | ||
exec(callback); | ||
}); | ||
} | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.view { | ||
height: 100%; | ||
font-size: 16px; | ||
white-space: pre; | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"upload", | ||
"operation", | ||
"konsole", | ||
"terminal", | ||
"cloud", [{ | ||
"name": "remote", | ||
"data": [{ | ||
|
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
Oops, something went wrong.