added better scripting support for ig repl...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-01-29 02:16:34 +03:00
parent cb6b45182f
commit cdd6689f22
2 changed files with 27 additions and 2 deletions

View File

@ -241,9 +241,29 @@ var CLIActions = actions.Actions({
// print banner...
//XXX
var code
repl
.start({
prompt: 'ig> ',
...(process.stdin.isTTY ?
// interactive...
{
prompt: 'ig> ',
}
// non-tty / non-interactive repl...
: {
terminal: false,
prompt: '',
// XXX HACK???
// 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' }
}),
useGlobal: true,
@ -253,6 +273,11 @@ var CLIActions = actions.Actions({
//ignoreUndefined: true,
})
.on('exit', function(){
// XXX HACK???
// run collected code...
if(code){
var AsyncFunction = (async function(){}).constructor
AsyncFunction(code)() }
that.stop() }) }],
// XXX move this to a feature that requires electron...
// ...and move electron to an optional dependency...

View File

@ -1,7 +1,7 @@
{
"name": "ImageGrid.Viewer.g4",
"main": "index.html",
"version": "4.0.5a",
"version": "4.0.6a",
"author": "Alex A. Naanou <alex.nanou@gmail.com> (https://github.com/flynx)",
"contributors": [],
"repository": "github:flynx/ImageGrid",