From a19391d0859f95efe843b95c7a6ed7e581a27e1c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 11 Dec 2018 17:18:02 +0300 Subject: [PATCH] reworking cli... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/cli.js | 20 ++++++++++++++++++-- ui (gen4)/features/core.js | 10 +++++++++- ui (gen4)/features/history.js | 2 +- ui (gen4)/ig.js | 6 +++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ui (gen4)/features/cli.js b/ui (gen4)/features/cli.js index 2b21efd6..12af4b78 100755 --- a/ui (gen4)/features/cli.js +++ b/ui (gen4)/features/cli.js @@ -114,6 +114,9 @@ module.CLI = core.ImageGridFeatures.Feature({ var argv = process.argv } + + var keep_running = false + // XXX this is not portable... //var package = requirejs('fs-extra').readJSONSync('./package.json') @@ -200,8 +203,7 @@ module.CLI = core.ImageGridFeatures.Feature({ }) .option('repl, --repl', 'start an ImageGrid REPL', function(){ - // XXX this is broken in node for some reason... - var repl = requirejs('repl') + var repl = nodeRequire('repl') // setup the global ns... global.ig = @@ -216,6 +218,8 @@ module.CLI = core.ImageGridFeatures.Feature({ repl.start({ prompt: 'ig> ', + useGlobal: true, + input: process.stdin, output: process.stdout, @@ -229,11 +233,15 @@ module.CLI = core.ImageGridFeatures.Feature({ // npm link nwjs // nw install 0.14.5-sdk .option('gui, --gui', 'start ImageGrid.Viewer', function(){ + throw new Error('ig: GUI startup not implemented.') + var path = requirejs('path') requirejs('child_process') .spawn(requirejs('nwjs'), [ path.dirname(process.argv[1]).replace(/\\/g, '/') + '/']) + + keep_running = true }) // XXX the problem with this is that it still tires @@ -251,11 +259,19 @@ module.CLI = core.ImageGridFeatures.Feature({ .action(function(action, args){ // XXX //console.log('>>>>', action, args, !!that[action]) + if(!that[action]){ + console.error('No such action:', action) + return + } that[action](args) }) .parse(argv) + + + !keep_running + && this.stop() }] ], }) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 4bc44197..c3a2f51a 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -323,7 +323,15 @@ var LifeCycleActions = actions.Actions({ return !this.__stop_handler }, isReady: function(){ return !!this.__ready }, - + // XXX is this the right name for this??? + get runtimeState(){ + return this.isStarted() ? + 'started' + : this.isStarted() ? + 'stopped' + : this.isReady() ? + 'ready' + : undefined }, start: ['- System/', doc`Start core action/event diff --git a/ui (gen4)/features/history.js b/ui (gen4)/features/history.js index e25b2e29..77b87c58 100755 --- a/ui (gen4)/features/history.js +++ b/ui (gen4)/features/history.js @@ -59,7 +59,7 @@ var URLHistoryActions = actions.Actions({ // will have no effect... get url_history_pinned(){ var url_history = this.url_history - return Object.keys(url_history) + return Object.keys(url_history || {}) .reduce(function(res, k){ if(url_history[k].pinned){ res[k] = url_history[k] diff --git a/ui (gen4)/ig.js b/ui (gen4)/ig.js index df6f8dd8..7f4a1d50 100755 --- a/ui (gen4)/ig.js +++ b/ui (gen4)/ig.js @@ -8,7 +8,11 @@ //var DEBUG = DEBUG != null ? DEBUG : true -//require('v8-compile-cache') +require('v8-compile-cache') +// NOTE: this fixes several issues with lib/util conflicting with stuff... +// XXX this might also pose some other issues within the repl, needs +// testing... +require('repl') require('./cfg/requirejs')