Пример #1
11
	// Finish the task in...
	setTimeout( done.bind( null , task ) , 500 + Math.random() * 1200 ) ;
	
	// Start another parallel task in...
	setTimeout( start , 400 + Math.random() * 400 ) ;
}


function done( task )
{
	progressBar.itemDone( task ) ;
	countDown -- ;
	
	// Cleanup and exit
	if ( ! countDown )
	{
		setTimeout( function() { term( '\n' ) ; process.exit() ; } , 200 ) ;
	}
}


progressBar = term.progressBar( {
	width: 80 ,
	title: 'Daily tasks:' ,
	eta: true ,
	percent: true ,
	items: thingsToDo.length
} ) ;

start() ;
                                
Пример #2
2
var progressBar , progress = 0 ;


function doProgress()
{
	// Add random progress
	progress += Math.random() / 10 ;
	progressBar.update( progress ) ;
	
	if ( progress >= 1 )
	{
		// Cleanup and exit
		setTimeout( function() { term( '\n' ) ; process.exit() ; } , 200 ) ;
	}
	else
	{
		setTimeout( doProgress , 100 + Math.random() * 400 ) ;
	}
}


progressBar = term.progressBar( {
	width: 80 ,
	title: 'Serious stuff in progress:' ,
	eta: true ,
	percent: true
} ) ;

doProgress() ;
                                
Пример #3
0
exports.term = function(proxy) {
  console.log('=> Now browse to http://localhost:%s', proxy.port)
  proxy.server.termEvents.on('start', port => console.log('\n----- starting server...'))
  proxy.server.termEvents.on('log', txt => term(txt))

  terminal.grabInput()

  term.on('key', function(key, matches, data) {
    if(key === 'CTRL_C') {
      exit()
    }
    else if(key === 'r' || key === 'R') {
      proxy.server.dirty()
      terminal.red('Reload server...\n')
    }
    else if(key === 'x' || key === 'X') {
      tasks.all.forEach(x => x.dirty())
      terminal.red('Restart build...\n')
    }
  })

  process.on('SIGINT', () => exit())
  process.on('uncaughtException', err => {
    terminal.red(`uncaughtException: ${err.message}\n`)
    console.error(err.stack)
    exit()
  })
}
Пример #4
0
const render = () => {
	term.fullscreen();
	term.inverse( padLine( 'Use the arrow keys and BACKSPACE to navigate, ENTER to select, and ESC to quit' ) );
	term( '\n' );
	term.bold( padLine( `--- ${ current.path } `, '-' ) );

	if ( menu ) {
		menu.abort();
	}

	menu = term.singleColumnMenu(
		getMenu( current, term.height - 4 ),
		{ selectedIndex: current.index },
		( error, { selectedIndex } ) => {
			const selectedDirectory = current.items[ selectedIndex ].name;
			const selectedPath = path.resolve( current.path, selectedDirectory );
			const stats = fs.statSync( selectedPath );

			if ( stats.isDirectory() ) {
				current = Folder( selectedPath );
			} else {
				current.index = selectedIndex;

				term.bell();
			}

			render();
		} );
};
Пример #5
0
            }, function(error, result){
                if(result){
                    var prod = checkInStock(input, inventory, function(prod){
                        if(prod[0] != null){

                            term.blue('There are ' + prod[0].StockQuantity + ' left in stock ')
                            term.blue('You have chosen to purchase ' + prod[0].ProductName + '\n');
                            var id = prod[0].ItemID;
                            var quantity = prod[0].StockQuantity - 1;
                            connection.query('UPDATE products SET StockQuantity= ' + quantity + ' WHERE ItemID='+ id +';', function(err, res){
                                if(err){
                                    console.error('error connectiong: ' + err.stack)
                                } else {
                                    term.green('You have successfully purchased a ' + prod[0].ProductName);
                                    process.exit();
                                }
                            })

                        } else {
                            term.blue('Sorry it looks like '+ input +' is out of stock. \n');
                            term.blue('We have ordered more of this item, check back soon');
                            promptCustomer(res);
                        }
                    });

                } else {
                    term.blue(input);
                    term.red('You do not want to purchase this item.')
                    process.exit()
                    promptCustomer(res)
                }
            })
Пример #6
0
 term.on('key', function(key, matches, data) {
   if(key === 'CTRL_C') {
     exit()
   }
   else if(key === 'r' || key === 'R') {
     proxy.server.dirty()
     terminal.red('Reload server...\n')
   }
   else if(key === 'x' || key === 'X') {
     tasks.all.forEach(x => x.dirty())
     terminal.red('Restart build...\n')
   }
 })
Пример #7
0
io.on('connection', function(socket){

	term.colorGrayscale(200)("Connection established, serving dummy data.").nextLine();

	var counter = 0;

	var intervalID = setInterval(function() {

		socket.emit("bodyFrame", array[counter]);
		counter++;

		if(counter >= array.length) {
			// reset counter.
			counter = 0;

			// advance to next file
			fileCounter++;
			workingFile = json.read(KINECT_DATA_FILES[fileCounter % KINECT_DATA_FILES.length]);
			array = workingFile.get('bodiesData');
		}

		frameCounter++;

		// arbitrarly large move back to hit start of line. (pending better way)
		term.eraseLine().blue("BodyFrame sent: " + frameCounter).move(-1000,0);

	}, 33);

	// disconnect event handler
	socket.on('disconnect', function() {
		// stop the interval timer
		clearInterval(intervalID);
		term.nextLine().bold.red("Disconnected from client.").nextLine();
	});
});
Пример #8
0
module.exports.boot = function(g,p){
    recents.init(term)
    get_last_msgs = g
    term.on('key',onkey)
    state = 'recents'
    post = p
}
term.on( 'key' , function( key ) {
	if ( key === 'CTRL_C' )
	{
		term.green( 'CTRL-C detected...\n' ) ;
		terminate() ;
	}
} ) ;
Пример #10
0
 connection.query('UPDATE products SET StockQuantity= ' + quantity + ' WHERE ItemID='+ id +';', function(err, res){
     if(err){
         console.error('error connectiong: ' + err.stack)
     } else {
         term.green('You have successfully purchased a ' + prod[0].ProductName);
         process.exit();
     }
 })
Пример #11
0
 connection.query('SELECT * FROM products', function(err, res){
     if(err) throw err;
     term.clear();
     var tab = '\t';
     inventory = res
     console.log("ItemID\tProduct Name\tDepartment\tPrice\t# In Stock");
     console.log("--------------------------------------------------------------------------------------------");
     for (var i = 0; i < res.length; i++) {
         autoComplete.push(res[i].ProductName);
         history.push(res[i].ProductName);
         if( res[i].StockQuantity > 0){
             term.green(res[i].ItemID + tab+ res[i].ProductName + tab + res[i].DepartmentName + tab + res[i].Price + tab + res[i].StockQuantity + '\n');
         } else {
             term.red(res[i].ItemID + tab + res[i].ProductName + tab + res[i].DepartmentName + tab + res[i].Price + tab + res[i].StockQuantity + '\n');
         };
     }
     promptCustomer(res);
 })
Пример #12
0
var printTweets = function(){
	term.slowTyping(
	  	term(latestTweets) ,
	  	{ 
	  		flashStyle: term.yellow,
			delay: 10, 
	  	},
	 	function(){ process.exit(); }
	 ); 

}
Пример #13
0
    return new Promise( (resolve, reject) => {

      // Start grabbing key presses
      term.grabInput()

      term.on('key', (keyname, matches, data) => {
        if (this.paused) {
          return
        }
        log.debug('keypress:', keyname, data)

        // Exit key
        if (keyname === 'CTRL_C') {
          resolve(this.disconnect())
          return
        }

        this.sendKey(this._normalizeKeyName(keyname))
      })
    })
Пример #14
0
 return new Promise( (resolve, reject) => {
   this._textInput = term.inputField( (error, input) => {
     term('\n')
     if (error) {
       log.error(error)
       reject(error)
     }
     else {
       resolve(input)
     }
     this.exitTextEntry()
   })
 })
Пример #15
0
term.on( 'key', ( name ) => {
	switch ( name ) {
		case 'BACKSPACE':
			const parentPath = path.dirname( current.path );

			if ( isProjectPath( parentPath ) ) {
				current = Folder( parentPath );

				render();
			} else {
				term.bell();
			}

			break;

		case 'ESCAPE':
			term.clear();
			term.processExit();

			break;
	}
} );
Пример #16
0
cli.request = async function( query ) {
	const HttpRequester = require( './HttpRequester.js' ) ;
	var streams = {} , incomingMessage , body ,
		httpRequester = new HttpRequester( query ) ;

	try {
		if ( query.output ) {
			streams.output = fs.createWriteStream( query.output ) ;
			await Promise.onceEventOrError( streams.output , 'open' ) ;
		}

		body = await httpRequester.performRequest( query , {
			output: streams.output ,
			headerCallback: incomingMessage_ => {
				incomingMessage = incomingMessage_ ;
				httpRequester.displayHeader( incomingMessage ) ;
			} ,
			progressCallback: httpRequester.displayProgressBar.bind( httpRequester , {} )
		} ) ;
	}
	catch( error ) {
		term.red( error.toString() + '\n' ) ;
		process.exit( 1 ) ;
	}

	term( '\n' ) ;

	if ( ! streams.output ) {
		httpRequester.displayBody( body , incomingMessage ) ;
		httpRequester.displayTrailer( incomingMessage ) ;
	}

	term.dim.magenta( '[Received ' +
	( body ? utils.byteString( body.length ) + ' ' : '' ) +
	'in ' + httpRequester.lastResponse.time + 'ms]\n' ) ;

	term.processExit( 0 ) ;
} ;
Пример #17
0
module.exports = function(args = {}) {
  try {
    pkg    = req('package.json');
  } catch(e) {
    term.red.error("There is no initialized project in this directory!\n");
    process.exit(e.code);
  }

  term.cyan("^_Project directory:\n");
  term(path.join(path.basename(cwd),"/") + "\n");
  // project name and version
  if (/^(version|name)$/.test(args[0]) || args[0] === undefined) {
    term.cyan("^_Project name:\n");
    term(pkg.name + " v" + pkg.version + "\n");
    if (args[0] !== undefined) process.exit(0);
  }
  // template version
  if (pkg.description && args[0] === "description" || args[0] === undefined) {
    term.cyan("^_Project description:\n");
    term(pkg.description + "\n");
  }

}
Пример #18
0
		( error, { selectedIndex } ) => {
			const selectedDirectory = current.items[ selectedIndex ].name;
			const selectedPath = path.resolve( current.path, selectedDirectory );
			const stats = fs.statSync( selectedPath );

			if ( stats.isDirectory() ) {
				current = Folder( selectedPath );
			} else {
				current.index = selectedIndex;

				term.bell();
			}

			render();
		} );
Пример #19
0
cli.wsMessages = async function( query ) {
	const HttpRequester = require( './HttpRequester.js' ) ;
	var messages ,
		httpRequester = new HttpRequester( query ) ;

	try {
		messages = await httpRequester.wsMessages() ;
	}
	catch ( error ) {
		term.red( error.toString() + '\n' ) ;
		process.exit( 1 ) ;
	}

	// Do something with those messages...
	process.exit( 0 ) ;
} ;
Пример #20
0
  startTextEntry: function () {
    this.pauseCapture()

    term.bold.yellow('\nKodi is requesting text input\n')
    term.bold('Enter text to send: ')

    return new Promise( (resolve, reject) => {
      this._textInput = term.inputField( (error, input) => {
        term('\n')
        if (error) {
          log.error(error)
          reject(error)
        }
        else {
          resolve(input)
        }
        this.exitTextEntry()
      })
    })
  },
Пример #21
0
	var intervalID = setInterval(function() {

		socket.emit("bodyFrame", array[counter]);
		counter++;

		if(counter >= array.length) {
			// reset counter.
			counter = 0;

			// advance to next file
			fileCounter++;
			workingFile = json.read(KINECT_DATA_FILES[fileCounter % KINECT_DATA_FILES.length]);
			array = workingFile.get('bodiesData');
		}

		frameCounter++;

		// arbitrarly large move back to hit start of line. (pending better way)
		term.eraseLine().blue("BodyFrame sent: " + frameCounter).move(-1000,0);

	}, 33);
Пример #22
0
cli.server = async function( serverConf ) {
	const HttpServer = require( './HttpServer.js' ) ;
	var httpServer = new HttpServer( serverConf ) ,
		streams = {} ;

	try {
		if ( serverConf.output ) {
			streams.output = fs.createWriteStream( serverConf.output ) ;
			await Promise.onceEventOrError( streams.output , 'open' ) ;
		}
	}
	catch( error ) {
		term.red( error.toString() + '\n' ) ;
		process.exit( 1 ) ;
	}

	//console.log( serverConf ) ;

	// /!\ Streams are unused ATM /!\
	httpServer.startServer( serverConf , streams ) ;
} ;
Пример #23
0
function terminate()
{
	term.grabInput( false ) ;
	// Add a 100ms delay, so the terminal will be ready when the process effectively exit, preventing bad escape sequences drop
	setTimeout( function() { process.exit() ; } , 100 ) ;
}
Пример #24
0
	function( error , input ) {

		term.green( "\nYour command is: '%s'\n" , input ) ;
		process.exit() ;
	}
Пример #25
0
term.inputField(
	{
		autoComplete: autoComplete ,
		autoCompleteHint: true ,
		autoCompleteMenu: true ,
		tokenHook: function( token , isEndOfInput , previousTokens , term , config ) {
			var previousText = previousTokens.join( ' ' ) ;
			
			switch ( token )
			{
				case 'sudo' :
					config.style = term.red ;
					return previousTokens.length ? null : term.bold.red ;
				case 'dnf' :
					return previousText === '' || previousText === 'sudo' ? term.brightMagenta : null ;
				case 'install' :
					config.style = term.brightBlue ;
					config.hintStyle = term.brightBlack.italic ;
					return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightYellow : null ;
				case 'search' :
					config.style = term.brightBlue ;
					return previousText === 'dnf' || previousText === 'sudo dnf' ? term.brightCyan : null ;
			}
		}
	} ,
	function( error , input ) {

		term.green( "\nYour command is: '%s'\n" , input ) ;
		process.exit() ;
	}
) ;
Пример #26
0
	var latestTweets;

	tweetClient.get('statuses/user_timeline', params, function(error, tweets, response){
		if (!error){
			for (var i = 0; i < 10; i++){
				 lastestTweets.push(tweets[i].text);
				 console.log(tweets[i].text)
			}
			
		}else{
			term(error)
		}
		
	});	// process.exit();
}
term.clear();	
// term.slowTyping(
// 	welcomeMsg,
// 	{
// 		flashStyle: term.yellow,
// 		delay:10
// 	},
// 	function(){
// 		process.exit();
// 	}
// );
var questions = [
  {
    type: 'message',
    name: 'first_name',
    message: 'What\'s your first name'
term.on( 'key' , key => {
	if ( key === 'CTRL_C' ) {
		term.grabInput( false ) ;
		process.exit() ;
	}
} ) ;
menu.on( 'submit' , data => {
	term.saveCursor() ;
	term.moveTo( 1 , term.height - 1 , "Submit: %s" , data.selectedText ) ;
	term.restoreCursor() ;
} ) ;
Пример #29
0
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
"use strict" ;

var term = require( 'terminal-kit' ).terminal ;

var items = [ 'File' , 'Edit' , 'View' , 'History' , 'Bookmarks' , 'Tools' , 'Help' ] ;

var options = {
	y: 1 ,	// the menu will be on the top of the terminal
	style: term.inverse ,
	selectedStyle: term.dim.blue.bgGreen
} ;

term.clear() ;

term.singleLineMenu( items , options , function( error , response ) {
	term( '\n' ).eraseLineAfter.green(
		"#%s selected: %s (%s,%s)\n" ,
		response.selectedIndex ,
		response.selectedText ,
		response.x ,
		response.y
	) ;
	process.exit() ;
} ) ;
	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
"use strict" ;

var term = require( 'terminal-kit' ).terminal ;

term.clear() ;
term.cyan( 'Where will you go?\n' ) ;

var items = [
	'a. Go north' ,
	'b. Go south' ,
	'c. Go east' ,
	'd. Go west'
] ;

var menu = term.singleColumnMenu( items , { continueOnSubmit: true } ) ;

menu.on( 'submit' , data => {
	term.saveCursor() ;
	term.moveTo( 1 , term.height - 1 , "Submit: %s" , data.selectedText ) ;
	term.restoreCursor() ;