mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19: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 | 					this.features.input | ||||||
| 					: tags), | 					: 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', | 	cliStartREPL: ['- System/CLI/start CLI interpreter', | ||||||
| 		{cli: { | 		{cli: { | ||||||
| 			name: '@repl', | 			name: '@repl', | ||||||
| @ -226,7 +253,6 @@ var CLIActions = actions.Actions({ | |||||||
| 		}}, | 		}}, | ||||||
| 		function(path, options){ | 		function(path, options){ | ||||||
| 			var that = this | 			var that = this | ||||||
| 			var repl = nodeRequire('repl') |  | ||||||
| 			var package = nodeRequire('./package.json') | 			var package = nodeRequire('./package.json') | ||||||
| 
 | 
 | ||||||
| 			// XXX SETUP
 | 			// XXX SETUP
 | ||||||
| @ -237,65 +263,43 @@ var CLIActions = actions.Actions({ | |||||||
| 
 | 
 | ||||||
| 			this.__keep_running = true | 			this.__keep_running = true | ||||||
| 
 | 
 | ||||||
| 			// setup the global ns...
 | 			this.setupGlobals() | ||||||
| 			global.ig = |  | ||||||
| 			global.ImageGrid =  |  | ||||||
| 				this |  | ||||||
| 			global.help = function(...actions){ |  | ||||||
| 				global.ig.help(...actions) } |  | ||||||
| 			//var features = global.ImageGridFeatures = core.ImageGridFeatures
 |  | ||||||
| 
 | 
 | ||||||
| 			// print banner...
 | 			// start non-tty / script mode...
 | ||||||
| 			var banner = this.banner  | 			if(!process.stdin.isTTY){ | ||||||
| 				|| this.config.banner | 				var fs = nodeRequire('fs') | ||||||
| 			banner | 				var AsyncFunction = (async function(){}).constructor | ||||||
| 				&& process.stdin.isTTY |  | ||||||
| 				&& process.stdout.isTTY |  | ||||||
| 				&& console.log(banner  |  | ||||||
| 					.replace(/\$APPNAME/g, package.name) |  | ||||||
| 					.replace(/\$AUTHOR/g, package.author) |  | ||||||
| 					.replace(/\$REPO/g, package.repository) |  | ||||||
| 					.replace(/\$SCRIPTNAME/g, this.argv.scriptName) |  | ||||||
| 					.replace(/\$VERSION/g, this.version)) |  | ||||||
| 
 | 
 | ||||||
| 			// start the repl...
 | 				AsyncFunction( | ||||||
| 			var code | 					fs.readFileSync(process.stdin.fd, 'utf-8'))() | ||||||
| 			repl | 				this.stop() | ||||||
| 				.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' } |  | ||||||
| 						}), |  | ||||||
| 
 | 
 | ||||||
| 					useGlobal: true, | 			// start repl mode...
 | ||||||
|  | 			} else { | ||||||
|  | 				var repl = nodeRequire('repl') | ||||||
|  | 				// print banner...
 | ||||||
|  | 				var banner = this.banner  | ||||||
|  | 					|| this.config.banner | ||||||
|  | 				banner | ||||||
|  | 					&& process.stdin.isTTY | ||||||
|  | 					&& process.stdout.isTTY | ||||||
|  | 					&& console.log(banner  | ||||||
|  | 						.replace(/\$APPNAME/g, package.name) | ||||||
|  | 						.replace(/\$AUTHOR/g, package.author) | ||||||
|  | 						.replace(/\$REPO/g, package.repository) | ||||||
|  | 						.replace(/\$SCRIPTNAME/g, this.argv.scriptName) | ||||||
|  | 						.replace(/\$VERSION/g, this.version)) | ||||||
| 
 | 
 | ||||||
| 					input: process.stdin, | 				// start the repl...
 | ||||||
| 					output: process.stdout, | 				repl | ||||||
| 
 | 					.start({ | ||||||
| 					//ignoreUndefined: true,
 | 						prompt: 'ig> ', | ||||||
| 				}) | 						useGlobal: true, | ||||||
| 				.on('exit', function(){ | 						input: process.stdin, | ||||||
| 					// run collected code...
 | 						output: process.stdout, | ||||||
| 					if(code){ | 					}) | ||||||
| 						var AsyncFunction = (async function(){}).constructor | 					.on('exit', function(){ | ||||||
| 						AsyncFunction(code)() } | 						that.stop() }) } }], | ||||||
| 					that.stop() }) }], |  | ||||||
| 	// XXX move this to a feature that requires electron...
 | 	// XXX move this to a feature that requires electron...
 | ||||||
| 	// 		...and move electron to an optional dependency...
 | 	// 		...and move electron to an optional dependency...
 | ||||||
| 	cliStartGUI: ['- System/CLI/start viewer GUI', | 	cliStartGUI: ['- System/CLI/start viewer GUI', | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user