mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
added $ ig do=CODE command...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6655907afd
commit
3ea3639cb6
@ -214,10 +214,37 @@ var CLIActions = actions.Actions({
|
||||
this.features.input
|
||||
: tags),
|
||||
]) }],
|
||||
setupGlobals: ['- System/',
|
||||
function(){
|
||||
// setup the global ns...
|
||||
global.ig =
|
||||
global.ImageGrid =
|
||||
this
|
||||
global.help = function(...actions){
|
||||
global.ig.help(...actions) }
|
||||
global.ImageGridFeatures = core.ImageGridFeatures }],
|
||||
|
||||
|
||||
// Startup commands...
|
||||
// basic code runner...
|
||||
// XXX should we handle/print errors here???
|
||||
cliDo: ['- System/CLI/run CODE',
|
||||
{cli: {
|
||||
name: '@do',
|
||||
arg: 'CODE'
|
||||
}},
|
||||
function(code){
|
||||
var AsyncFunction = (async function(){}).constructor
|
||||
|
||||
this.setupFeatures()
|
||||
this.setupGlobals()
|
||||
|
||||
AsyncFunction(code)()
|
||||
|
||||
this.stop() }],
|
||||
|
||||
// Interactive commands...
|
||||
//
|
||||
// XXX should we handle/print errors in script mode here???
|
||||
cliStartREPL: ['- System/CLI/start CLI interpreter',
|
||||
{cli: {
|
||||
name: '@repl',
|
||||
@ -226,7 +253,6 @@ var CLIActions = actions.Actions({
|
||||
}},
|
||||
function(path, options){
|
||||
var that = this
|
||||
var repl = nodeRequire('repl')
|
||||
var package = nodeRequire('./package.json')
|
||||
|
||||
// XXX SETUP
|
||||
@ -237,14 +263,20 @@ var CLIActions = actions.Actions({
|
||||
|
||||
this.__keep_running = true
|
||||
|
||||
// setup the global ns...
|
||||
global.ig =
|
||||
global.ImageGrid =
|
||||
this
|
||||
global.help = function(...actions){
|
||||
global.ig.help(...actions) }
|
||||
//var features = global.ImageGridFeatures = core.ImageGridFeatures
|
||||
this.setupGlobals()
|
||||
|
||||
// start non-tty / script mode...
|
||||
if(!process.stdin.isTTY){
|
||||
var fs = nodeRequire('fs')
|
||||
var AsyncFunction = (async function(){}).constructor
|
||||
|
||||
AsyncFunction(
|
||||
fs.readFileSync(process.stdin.fd, 'utf-8'))()
|
||||
this.stop()
|
||||
|
||||
// start repl mode...
|
||||
} else {
|
||||
var repl = nodeRequire('repl')
|
||||
// print banner...
|
||||
var banner = this.banner
|
||||
|| this.config.banner
|
||||
@ -259,43 +291,15 @@ var CLIActions = actions.Actions({
|
||||
.replace(/\$VERSION/g, this.version))
|
||||
|
||||
// start the repl...
|
||||
var code
|
||||
repl
|
||||
.start({
|
||||
...(process.stdin.isTTY ?
|
||||
// interactive...
|
||||
{ prompt: 'ig> ', }
|
||||
// non-tty / non-interactive repl...
|
||||
// NOTE: this is handled by node's repl to avoid
|
||||
// handling extra stuff here...
|
||||
// XXX is this necessary???
|
||||
: {
|
||||
terminal: false,
|
||||
prompt: '',
|
||||
// collect the code...
|
||||
// NOTE: we are using a custom eval here as it
|
||||
// seems that there is no way to either
|
||||
// disable the default writer or to define
|
||||
// an alternative that would not output \n's
|
||||
// per non-empty line of input...
|
||||
eval: function(cmd, context, filename, callback) {
|
||||
code = code ?? ''
|
||||
code += cmd + '\n' }
|
||||
}),
|
||||
|
||||
prompt: 'ig> ',
|
||||
useGlobal: true,
|
||||
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
|
||||
//ignoreUndefined: true,
|
||||
})
|
||||
.on('exit', function(){
|
||||
// run collected code...
|
||||
if(code){
|
||||
var AsyncFunction = (async function(){}).constructor
|
||||
AsyncFunction(code)() }
|
||||
that.stop() }) }],
|
||||
that.stop() }) } }],
|
||||
// XXX move this to a feature that requires electron...
|
||||
// ...and move electron to an optional dependency...
|
||||
cliStartGUI: ['- System/CLI/start viewer GUI',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user