mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-23 02:48:21 +00:00
fix: dashboard auto complete
This commit is contained in:
parent
ea7ae22501
commit
c51ec5029b
@ -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),
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user