fix: dashboard auto complete

This commit is contained in:
Andre Medeiros 2019-04-22 17:22:02 -04:00 committed by Iuri Matias
parent ea7ae22501
commit c51ec5029b
2 changed files with 46 additions and 1 deletions

View File

@ -43,8 +43,49 @@ class REPL {
return inspectedOutput;
}
complete(partial, cb) {
// no function calls
if (partial.indexOf('(') !== -1) {
return cb(null, [[], partial]);
}
const lastDot = partial.lastIndexOf('.');
let context = partial.substr(0, lastDot);
let hint = partial.substr(lastDot + 1);
if (lastDot === -1) {
context = 'this';
hint = partial;
}
this.events.request('console:executeCmd', context, (err, result) => {
if (err !== null) {
cb(err, [[], partial]);
}
let props = Object
.getOwnPropertyNames(result)
.sort();
if (hint !== "") {
props = props.filter(prop => { return prop.indexOf(hint) === 0; });
}
if (lastDot !== -1) {
props = props.map(prop => { return `${context}.${prop}`; });
}
if (props.length > 1) {
console.log(props.join(', '));
}
cb(null, [props, partial]);
});
}
start(done) {
this.replServer = repl.start({
completer: this.complete.bind(this),
prompt: "Embark (".cyan + this.env.green + ") > ".cyan,
useGlobal: true,
eval: this.enhancedEval.bind(this),

View File

@ -568,7 +568,11 @@ function jsonFunctionReplacer(_key, value) {
function getWindowSize() {
const windowSize = require('window-size');
return windowSize.get();
if (windowSize) {
return windowSize.get();
}
return {width: 240, height: 75};
}
function toposort(graph) {