|
|
@ -83,7 +83,7 @@ var css = csjs` |
|
|
|
.info { |
|
|
|
.info { |
|
|
|
color : blue; |
|
|
|
color : blue; |
|
|
|
} |
|
|
|
} |
|
|
|
.log { |
|
|
|
.default { |
|
|
|
color : white; |
|
|
|
color : white; |
|
|
|
} |
|
|
|
} |
|
|
|
.ghostbar { |
|
|
|
.ghostbar { |
|
|
@ -194,6 +194,10 @@ class Terminal { |
|
|
|
self.event = new EventManager() |
|
|
|
self.event = new EventManager() |
|
|
|
self._api = opts.api |
|
|
|
self._api = opts.api |
|
|
|
self._view = { panel: null, bar: null, input: null, term: null, log: null, cli: null } |
|
|
|
self._view = { panel: null, bar: null, input: null, term: null, log: null, cli: null } |
|
|
|
|
|
|
|
self._templates = {} |
|
|
|
|
|
|
|
self._templates.default = self._blocksRenderer('default') |
|
|
|
|
|
|
|
self._templates.error = self._blocksRenderer('error') |
|
|
|
|
|
|
|
self._templates.info = self._blocksRenderer('info') |
|
|
|
if (opts.shell) self._shell = opts.shell |
|
|
|
if (opts.shell) self._shell = opts.shell |
|
|
|
// @TODO: listen to all relevant events
|
|
|
|
// @TODO: listen to all relevant events
|
|
|
|
// var events = opts.events
|
|
|
|
// var events = opts.events
|
|
|
@ -337,49 +341,48 @@ class Terminal { |
|
|
|
editable.focus() |
|
|
|
editable.focus() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_log (mode) { |
|
|
|
_blocksRenderer (mode) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
var modes = { log: true, info: true, error: true } |
|
|
|
var modes = { log: true, info: true, error: true } |
|
|
|
if (modes[mode]) { |
|
|
|
if (modes[mode]) { |
|
|
|
return function logger () { |
|
|
|
return function render () { |
|
|
|
var args = [].slice.call(arguments) |
|
|
|
var args = [].slice.call(arguments) |
|
|
|
self.data.session.push(args) |
|
|
|
|
|
|
|
var types = args.map(type) |
|
|
|
var types = args.map(type) |
|
|
|
var values = javascriptserialize.apply(null, args).map(function (x, i) { |
|
|
|
var values = javascriptserialize.apply(null, args).map(function (val, idx) { |
|
|
|
return (typeof args[i] === 'string') ? args[i] : x |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
values.forEach(function (val, idx) { |
|
|
|
|
|
|
|
if (types[idx] === 'element') val = jsbeautify.html(val) |
|
|
|
if (types[idx] === 'element') val = jsbeautify.html(val) |
|
|
|
var pattern = '.{1,' + self.data.lineLength + '}' |
|
|
|
var pattern = '.{1,' + self.data.lineLength + '}' |
|
|
|
var lines = val.match(new RegExp(pattern, 'g')) |
|
|
|
var lines = val.match(new RegExp(pattern, 'g')) |
|
|
|
var block = yo` |
|
|
|
return lines.map(str => document.createTextNode(`${str}\n`)) |
|
|
|
<div class="${css.block} ${css[mode]}"> |
|
|
|
|
|
|
|
${lines.map(str => { |
|
|
|
|
|
|
|
return document.createTextNode(`${str}\n`) |
|
|
|
|
|
|
|
})} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
self._view.log.appendChild(block) |
|
|
|
|
|
|
|
self.scroll2bottom() |
|
|
|
|
|
|
|
return lines |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
return values |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
throw new Error('mode is not supported') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
log () { |
|
|
|
registerType (typename, template) { |
|
|
|
var self = this |
|
|
|
|
|
|
|
var logger = self._log('log') |
|
|
|
|
|
|
|
return logger.apply(self, arguments) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
info () { |
|
|
|
|
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
var logger = self._log('info') |
|
|
|
if (typeof template !== 'function') throw new Error('invalid template') |
|
|
|
return logger.apply(self, arguments) |
|
|
|
self._template[typename] = template |
|
|
|
} |
|
|
|
} |
|
|
|
error () { |
|
|
|
log () { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
var logger = self._log('error') |
|
|
|
var args = [...arguments] |
|
|
|
return logger.apply(self, arguments) |
|
|
|
self.data.session.push(args) |
|
|
|
|
|
|
|
args.forEach(function (data = {}) { |
|
|
|
|
|
|
|
if (!data.type) data = { type: 'default', value: data } |
|
|
|
|
|
|
|
var render = self._templates[data.type] |
|
|
|
|
|
|
|
if (!render) render = self._templates.default |
|
|
|
|
|
|
|
var blocks = render(data.value) |
|
|
|
|
|
|
|
blocks.forEach(function (block) { |
|
|
|
|
|
|
|
self._view.log.appendChild(yo` |
|
|
|
|
|
|
|
<div class="${css.block} ${css[data.type] || data.type}"> |
|
|
|
|
|
|
|
${block} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
self.scroll2bottom() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
scroll2bottom () { |
|
|
|
scroll2bottom () { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|