Beispiel #1
0
cli.confToServerConf = function( args ) {
	var serverConf = tree.extend( { deep: true } , {} , args ) ;

	delete serverConf.shell ;

	// short-option substitution
	if ( serverConf.p ) { serverConf.port = serverConf.p ; delete serverConf.p ; }

	// shortcuts
	if ( serverConf.http ) { serverConf.protocol = 'http' ; delete serverConf.http ; }
	if ( serverConf.https ) { serverConf.protocol = 'https' ; delete serverConf.https ; }
	if ( serverConf.ws ) { serverConf.protocol = 'ws' ; delete serverConf.ws ; }


	if ( ! serverConf.responses ) { serverConf.responses = [] ; }

	if ( serverConf[ 'default-response' ] ) {
		serverConf.defaultResponse = serverConf[ 'default-response' ] ;
		delete serverConf[ 'default-response' ] ;
	}

	if ( ! serverConf.defaultResponse ) {
		serverConf.defaultResponse = {
			status: 404 ,
			headers: {} ,
			body: "404: Not Found."
		} ;
	}

	// Defaults...
	if ( ! serverConf.protocol ) { serverConf.protocol = 'http' ; }
	//if ( ! serverConf.hostname ) { serverConf.hostname = 'localhost' ; }
	if ( ! serverConf.port ) { serverConf.port = serverConf.protocol === 'https' ? 443 : 80 ; }

	return serverConf ;
} ;
Beispiel #2
0
var cli = module.exports = function() {
	var args , config = {} , query , serverConf , configName = '' ;

	/* eslint-disable indent */
	cliManager.package( require( '../package.json' ) )
		.app( 'HTTP Requester' )
		.baseline( "Perform HTTP & WS requests ^M^+like a boss!" )
		.usage( "[--parameter1 value1] [--parameter2 value2] [...]" )
		.introIfTTY
		.helpOption
		//.camel
		.opt( 'shell' ).flag
			.description( "Run requests in an interactive shell, ^M^+like a boss!" )
		.opt( 'method' ).string
			.typeLabel( 'method' )
			.description( "Set the HTTP method" )
		.opt( 'protocol' ).string
			.typeLabel( 'http|https|ws' )
			.description( "Set the protocol, 'http', 'https' or 'ws'" )
		.opt( 'host' ).string
			.typeLabel( 'host' )
			.description( "Set the targeted host" )
		.opt( [ 'port' , 'p' ] ).number
			.typeLabel( 'port-number' )
			.description( "Set the targeted port, default is 80 (HTTP) or 443 (HTTPS)" )
		.opt( 'path' ).string
			.typeLabel( 'path' )
			.description( "Set the path of the targeted resource in the host" )
		.opt( 'url' ).string
			.typeLabel( 'URL' )
			.description( "The full URL of the resource, will be splitted into protocol, host, port and path" )
		.opt( 'headers' )
			.typeLabel( 'json|object' )
			.description( "Specify all headers using a JSON string, or specify each header with the object syntax."
				+ "Any header can be specified as an option, e.g. ^b--headers.content-type application/json^c. "
				+ "Also if it is not conflicting with another options, it can be used without prefix, like ^b--content-type application/json" )
		.opt( 'auth' ).string
			.typeLabel( 'user:password' )
			.description( 'Basic authentication i.e. "user:password" to compute an Authorization header' )
		.opt( 'timeout' ).number
			.typeLabel( 'ms' )
			.description( "Set the request timeout in ms" )
		.opt( [ 'output' , 'o' ] ).string
			.typeLabel( 'file' )
			.description( "If given, the body's response will be written to this file instead of STDOUT" )
		.opt( 'http' ).flag
			.description( "Shortcut for ^b--protocol http" )
		.opt( 'https' ).flag
			.description( "Shortcut for ^b--protocol https" )
		.opt( 'ws' ).flag
			.description( "Shortcut for ^b--protocol ws" )
		.opt( [ 'breautify' , 'b' ] ).flag
			.description( "Beautify JSON body" )
		.opt( 'server' ).flag
			.description( "Start a server" )
		.opt( 'config' ).string
			.typeLabel( 'file' )
			.description( "A JSON or KFG config file containing all the above options, structured in an object" )
		.opt( 'rc' , true ).flag
			.description( "When set (the default), read the rc file in the user home directory" )
		.restArgs( 'restArgs' )
			.description( "Syntactic sugar, see below" )
		.details( "^+Syntactic sugar:^:\n"
			+ "  ^Khttp-requester                  ^claunch the interactive shell, like ^bhttp-requester --shell^:\n"
			+ "  ^Khttp-requester <file>           ^cload a config file, like ^bhttp-requester --config <file>^:\n"
			+ "  ^Khttp-requester <url>            ^cGET the url, like ^bhttp-requester --method get --url <url>^:\n"
			+ "  ^Khttp-requester <method> <url>   ^crequest the url, like ^bhttp-requester --method <method> --url <url>^:\n" ) ;
	/* eslint-enable indent */

	args = cliManager.run() ;

	if ( process.argv.length === 2 || ( process.argv.length === 3 && process.argv[ 2 ] === '--no-rc' ) ) {
		args.shell = true ;
	}

	// We should process the config argument beforehand
	if ( args.restArgs && args.restArgs.length === 1 ) {
		args.restArgs[ 0 ] = '' + args.restArgs[ 0 ] ;	// Force a string here
		if ( ! args.restArgs[ 0 ].match( /:\/\// ) ) { args.config = args.restArgs[ 0 ] ; }
	}

	// Load the config, if any
	if ( args.config ) {
		try {
			config = kungFig.load( args.config ) ;
			configName = path.basename( path.dirname( path.dirname( args.config ) ) ) ;
		}
		catch ( error ) {
			term.red( error.toString() + '\n' ) ;
			process.exit( 1 ) ;
		}

		delete args.config ;
	}
	else if ( args.rc ) {
		try {
			config = kungFig.load( path.join( process.cwd() , '.http-requester' , 'config.kfg' ) ) ;
			configName = path.basename( process.cwd() ) ;
		}
		catch ( error ) {
			// That's not an error
			try {
				config = kungFig.load( path.join( httpRequesterDir , 'config.kfg' ) ) ;
				if ( ! config ) { config = {} ; }
			}
			catch ( error_ ) {
				// That's not an error
				cli.createHomeConfig() ;
				config = {} ;
			}
		}
	}

	if ( ! config.configName ) { config.configName = configName ; }
	config.httpRequesterDir = httpRequesterDir ;

	delete args.rc ;

	tree.extend( { deep: true } , config , args ) ;

	if ( config.server ) {
		serverConf = cli.confToServerConf( config ) ;
		cli.server( serverConf ) ;
		return ;
	}

	query = cli.confToQuery( config ) ;

	if ( config.shell ) {
		cli.shell( query ) ;
		return ;
	}

	if ( query.protocol === 'ws' ) {
		cli.wsMessages( query ) ;
		return ;
	}

	cli.request( query ) ;
} ;
Beispiel #3
0
module.exports = function fileInput( options , callback )
{
	if ( arguments.length <= 0 ) { throw new Error( '[terminal] .fileInput(): should at least provide one callback as argument' ) ; }
	if ( arguments.length === 1 ) { callback = options ; options = {} ; }
	if ( ! options || typeof options !== 'object' ) { options = {} ; }
	
	var self = this , baseDir ;
	
	if ( options.baseDir )
	{
		baseDir = path.resolve( options.baseDir ) ;
		
		if ( ! path.isAbsolute( baseDir ) )
		{
			fs.realpath( options.baseDir , function( error , resolvedPath ) {
				if ( error ) { callback( error ) ; return ; }
				options.baseDir = resolvedPath ;
				fileInput.call( self , options , callback ) ;
			} ) ;
			
			return ;
		}
	}
	else
	{
		baseDir = process.cwd() ;
	}
	
	if ( baseDir[ baseDir.length - 1 ] !== '/' ) { baseDir += '/' ; }
	
	var autoCompleter = function autoCompleter( inputString , callback )
	{  
		var inputDir , inputFile , currentDir ;
		
		if ( inputString[ inputString.length - 1 ] === '/' )
		{
			inputDir = inputString ;
			inputFile = '' ;
		}
		else
		{
			inputDir = path.dirname( inputString ) ;
			inputDir = inputDir === '.' ? '' : inputDir + '/' ;
			inputFile = path.basename( inputString ) ;
		}
		
		
		// If the input start with a '/', then forget about the baseDir
		if ( path.isAbsolute( inputString ) ) { currentDir = inputDir ; }
		else { currentDir = baseDir + inputDir ; }
		
		
		//console.error( "### '" + inputDir +"' '"+ inputFile +"' '"+ currentDir + "'" ) ;
		
		readdir( currentDir , function( error , files ) {
			if ( error || ! Array.isArray( files ) || ! files.length ) { callback( undefined , inputString ) ; return ; }
			
			var completion = autoComplete( files , inputFile , true ) ;
			
			// force inputField() to prefix that *AFTER* singleLineMenu()
			if ( Array.isArray( completion ) ) { completion.prefix = inputDir ;	}
			else { completion = path.normalize( inputDir + completion ) ; }
			
			callback( undefined , completion ) ;
		} ) ;
	} ;
	
	// Transmit options to inputField()
	tree.extend( null , options , { autoComplete: autoCompleter , autoCompleteMenu: true , minLength: 1 } ) ;
	
	this.inputField(
		options ,
		function( error , input ) {
			if ( error ) { callback( error ) ; return ; }
			else if ( ! input && typeof input !== 'string' ) { callback() ; return ; }
			
			callback( undefined ,
				path.resolve( path.isAbsolute( input ) ? input : baseDir + input )
			) ;
		}
	) ;
} ;
Beispiel #4
0
cli.confToQuery = function( args ) {
	var key , splitted , indexOf ,
		query = tree.extend( { deep: true } , {} , args ) ;

	for ( key in query ) {
		if ( typeof cli.availableOptions[ key ] === 'string' ) {
			// Substitution
			query[ cli.availableOptions[ key ] ] = query[ key ] ;
			delete query[ key ] ;
		}
	}
	// /!\ The order matters! /!\

	delete query.shell ;

	if ( query.host ) {
		splitted = query.host.split( ':' ) ;
		query.hostname = splitted[ 0 ] ;

		if ( splitted[ 1 ] ) { query.port = splitted[ 1 ] ; }

		delete query.host ;
	}

	// shortcuts
	if ( query.http ) { query.protocol = 'http' ; delete query.http ; }
	if ( query.https ) { query.protocol = 'https' ; delete query.https ; }
	if ( query.ws ) { query.protocol = 'ws' ; delete query.ws ; }

	// Process arguments not belonging to any options
	if ( args.restArgs && args.restArgs.length === 1 && args.restArgs[ 0 ].match( /:\/\// ) ) {
		utils.urlToQuery( query.restArgs[ 0 ] , query , true ) ;
	}
	else if ( args.restArgs && query.restArgs.length === 2 ) {
		query.method = query.restArgs[ 0 ] ;

		if ( query.restArgs[ 1 ][ 0 ] === '/' ) { query.path = query.restArgs[ 1 ] ; }
		else { utils.urlToQuery( query.restArgs[ 1 ] , query , true ) ; }
	}

	delete query.restArgs ;


	// URL options
	if ( query.url ) {
		utils.urlToQuery( query.url , query , true ) ;
		delete query.url ;
	}


	// If no protocol, set 'http' as default
	if ( ! query.protocol ) { query.protocol = 'http' ; }


	if ( query.protocol === 'http' || query.protocol === 'https' ) {
		// Method
		if ( ! query.method ) { query.method = 'GET' ; }
		else { query.method = query.method.toUpperCase() ; }


	}
	else if ( query.protocol === 'ws' ) {
		if ( ! query.messages ) { query.messages = [] ; }
		if ( ! query.closeMatch ) { query.closeMatch = { count: query.messages.length } ; }
	}


	// Process headers options
	if ( typeof query.headers === 'string' ) {
		try {
			query.headers = JSON.parse( query.headers ) ;
		}
		catch ( error ) {
			query.headers = undefined ;
		}
	}

	if ( ! query.headers || typeof query.headers !== 'object' ) { query.headers = {} ; }

	for ( key in query ) {
		if ( ! cli.availableOptions[ key ] ) {
			// Any options that are not recognized are turned to header
			query.headers[ key ] = query[ key ] ;
			delete query[ key ] ;
		}
	}

	// Finally, normalize headers
	utils.normalizeHeaders( query.headers ) ;


	// Defaults...
	if ( ! query.hostname ) { query.hostname = 'localhost' ; }
	if ( ! query.port ) { query.port = query.protocol === 'https' ? 443 : 80 ; }
	if ( ! query.timeout ) { query.timeout = 10000 ; }	// 10 seconds
	if ( ! query.cwd ) { query.cwd = process.cwd() ; }

	if ( ! query.path ) {
		if ( query.pathname ) { query.path = query.pathname ; }
		else { query.path = '/' ; }
	}

	if ( ! query.pathname ) {
		query.pathname = query.path.split( '?' )[ 0 ] ;
	}

	if ( ! query.search ) {
		if ( ( indexOf = query.path.indexOf( '?' ) ) !== -1 ) {
			query.search = query.path.slice( indexOf ) ;
		}
	}


	return query ;
} ;
Beispiel #5
0
	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.
*/



var tree = require( 'tree-kit' ) ;
var xterm256 = require( './xterm-256color.js' ) ;
var rxvt = require( './rxvt.js' ) ;

var	esc = tree.extend( { own: true } , Object.create( xterm256.esc ) , rxvt.esc , {
	
	color24bits: { on: '%D%D%D' , na: true } ,	// not capable
	bgColor24bits: { on: '%D%D%D' , na: true }	// not capable
} ) ;


// So far, we derivate from xterm-256color and then just add specific things (owned properties)
// of rxvt, thus we achieve a clean inheritance model without duplicated code.

module.exports = {
	esc: esc ,
	keymap: tree.extend( { own: true } , Object.create( xterm256.keymap ) , rxvt.keymap ) ,
	handler: tree.extend( { own: true } , Object.create( xterm256.handler ) , rxvt.handler ) ,
	colorRegister: rxvt.colorRegister
} ;
var esc = tree.extend( null , Object.create( xterm.esc ) , {
	
	color256: { on: '\x1b[38;5;%um' , off: defaultColor } ,
	bgColor256: { on: '\x1b[48;5;%um' , off: bgDefaultColor } ,
	
	setCursorColorRgb: { on: '\x1b]12;#%x%x%x\x07' } ,	// it want rgb as parameter, like rgb:127/0/32
	setDefaultColorRgb: { on: '\x1b]10;#%x%x%x\x07' } ,	// ->|TODOC|<- not widely supported
	setDefaultBgColorRgb: { on: '\x1b]11;#%x%x%x\x07' } ,	// ->|TODOC|<- not widely supported
	color24bits: { on: '\x1b[38;2;%u;%u;%um' , off: defaultColor , fb: true } ,
	bgColor24bits: { on: '\x1b[48;2;%u;%u;%um' , off: bgDefaultColor , fb: true } ,
	
	// Cannot find a way to set the cursor to a register, so try to guess
	setCursorColor: {
		on: '%[setCursorColor:%a%a]F' ,
		handler: function setCursorColor( bg , fg ) {
			
			if ( typeof fg !== 'number' || typeof bg !== 'number' ) { return '' ; }
			
			fg = Math.floor( fg ) ;
			bg = Math.floor( bg ) ;
			
			if ( fg < 0 || fg > 255 || bg < 0 || bg > 255 ) { return '' ; }
			
			var rgb = this.root.rgbForRegister( bg ) ;
			
			return string.format( this.root.esc.setCursorColorRgb.on , rgb.r , rgb.g , rgb.b ) ;
		}
	}
} ) ;

var tree = require( 'tree-kit' ) ;
var xterm256 = require( './xterm-256color.js' ) ;
var gnome = require( './gnome.js' ) ;



// Remove colors
var defaultColor = '\x1b[39m' ; // back to the default color, most of time it is the same than .white
var bgDefaultColor = '\x1b[49m' ;   // back to the default color, most of time it is the same than .bgBlack


var	esc = tree.extend( { own: true } , Object.create( xterm256.esc ) , gnome.esc , {
	
	color24bits: { on: '\x1b[38;2;%u;%u;%um' , off: defaultColor } ,
	bgColor24bits: { on: '\x1b[48;2;%u;%u;%um' , off: bgDefaultColor }
} ) ;


// So far, we derivate from xterm-256color and then just add specific things (owned properties)
// of gnome, thus we achieve a clean inheritance model without duplicated code.

module.exports = {
	esc: esc ,
	keymap: tree.extend( { own: true } , Object.create( xterm256.keymap ) , gnome.keymap ) ,
	handler: tree.extend( { own: true } , Object.create( xterm256.handler ) , gnome.handler ) ,
	support: {
		deltaEscapeSequence: true ,
		"256colors": true ,
		"24bitsColors": true
Beispiel #8
0
var esc = tree.extend( null , Object.create( xterm.esc ) , {
	
	// Clear screen
	clear: { on: '\x1b[H\x1b[J' } ,
	
	// Linux console doesn't have bright color code, they are produced using 'bold' (which is not bold, by the way...)
	defaultColor: { on: defaultColor } ,
	brightBlack: { on: bold + '\x1b[30m' , off: defaultColor } ,
	brightRed: { on: bold + '\x1b[31m' , off: defaultColor } ,
	brightGreen: { on: bold + '\x1b[32m' , off: defaultColor } ,
	brightYellow: { on: bold + '\x1b[33m' , off: defaultColor } ,
	brightBlue: { on: bold + '\x1b[34m' , off: defaultColor } ,
	brightMagenta: { on: bold + '\x1b[35m' , off: defaultColor } ,
	brightCyan: { on: bold + '\x1b[36m' , off: defaultColor } ,
	brightWhite: { on: bold + '\x1b[37m' , off: defaultColor } ,
	brightColor: { on: bold + '\x1b[3%um' , off: defaultColor } ,	// should be called with a 0..7 integer
	
	// Linux console doesn't have bright bg color code, they are produced using 'blink' (which does not blink, by the way...)
	bgDefaultColor: { on: bgDefaultColor } ,
	bgBrightBlack: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,
	bgBrightRed: { on: blink + '\x1b[41m' , off: bgDefaultColor } ,
	bgBrightGreen: { on: blink + '\x1b[42m' , off: bgDefaultColor } ,
	bgBrightYellow: { on: blink + '\x1b[43m' , off: bgDefaultColor } ,
	bgBrightBlue: { on: blink + '\x1b[44m' , off: bgDefaultColor } ,
	bgBrightMagenta: { on: blink + '\x1b[45m' , off: bgDefaultColor } ,
	bgBrightCyan: { on: blink + '\x1b[46m' , off: bgDefaultColor } ,
	bgBrightWhite: { on: blink + '\x1b[47m' , off: bgDefaultColor } ,
	bgBrightColor: { on: blink + '\x1b[4%um' , off: bgDefaultColor } ,	// should be called with a 0..7 integer
	
	// Those either does not produce anything or switch to some arbitrary color, so we will use our own settings instead
	dim: { on: bold + '\x1b[30m' , off: defaultColor } ,	// dim does not produce dim, so we use brightBlack instead
	underline: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,	// underline does not produce underline, so we use bgBrightBlack instead
	italic: { on: '\x1b[1m' , off: '\x1b[22m' } ,	// italic does not produce italic, so we use bold instead (which is no bold but bright BTW)
	hidden: { on: '\x1b[40m\x1b[30m' , off: '\x1b[49m\x1b[39m' } ,	// hidden does not produce hidden, so we use black + bgBlack instead
	strike: { on: bold + '\x1b[30m' , off: defaultColor } ,	// strike does not produce strike, so we use brightBlack instead
	
	// Cursor styles
	hideCursor: { on: '\x1b[?1c' , off: '\x1b[?0c' } ,
	blockCursor: { on: '\x1b[?16;0;16c' } ,
	blinkingBlockCursor: { on: '\x1b[?6c' } ,
	underlineCursor: { on: '\x1b[?2c' } ,	// it's blinking anyway
	blinkingUnderlineCursor: { on: '\x1b[?2c' } ,
	beamCursor: { on: '' } ,	// do not exists
	blinkingBeamCursor: { on: '' } ,	// do not exists
	
			/* OSC */
	
	// Does not exist, silently drop it...
	windowTitle: { on: '%D' } ,
	
	setDefaultColorRgb: { on: '\x1b]P7%x%x%x' } ,
	setDefaultBgColorRgb: { on: '\x1b]P0%x%x%x' } ,
	setColorLL: { on: '\x1b]P%h%x%x%x' } ,
	setFont: { on: '%D' } ,	// not possible?
	requestColor: { on: '%D' , na: true } ,	// not capable
	
			/* Functions */
	
	color256: {
		on: '%[color256:%a]' ,
		off: defaultColor ,
		fb: true ,
		handler: function color256( register ) {
			
			if ( typeof register !== 'number' ) { return '' ; }
			if ( register < 0 || register > 255 ) { return '' ; }
			
			// If the register is greater than 15, find the 0..15 register that is close to it
			if ( register > 15 )
			{
				register = this.root.registerForRgb( this.root.rgbForRegister( register ) , 0 , 15 ) ;
			}
			
			return string.format.call( this.root.escHandler , this.root.esc.color.on , register ) ;
		}
	} ,
	
	bgColor256: {
		on: '%[bgColor256:%a]' ,
		off: bgDefaultColor ,
		fb: true ,
		handler: function bgColor256( register ) {
			
			if ( typeof register !== 'number' ) { return '' ; }
			if ( register < 0 || register > 255 ) { return '' ; }
			
			// If the register is greater than 15, find the 0..15 register that is close to it
			if ( register > 15 )
			{
				register = this.root.registerForRgb( this.root.rgbForRegister( register ) , 0 , 15 ) ;
			}
			
			return string.format.call( this.root.escHandler , this.root.esc.bgColor.on , register ) ;
		}
	} ,
	
	setCursorColor: {
		on: '%[setCursorColor:%a%a]' ,
		handler: function setCursorColor( bg , fg ) {
			
			if ( typeof fg !== 'number' || typeof bg !== 'number' ) { return '' ; }
			
			fg = Math.floor( fg ) ;
			bg = Math.floor( bg ) ;
			
			if ( fg < 0 || fg > 255 || bg < 0 || bg > 255 ) { return '' ; }
			
			// If the register is greater than 15, find the 0..15 register that is close to it
			if ( fg > 15 ) { fg = this.root.registerForRgb( this.root.rgbForRegister( fg ) , 0 , 15 ) ; }
			if ( bg > 15 ) { bg = this.root.registerForRgb( this.root.rgbForRegister( bg ) , 0 , 15 ) ; }
			
			//console.log( 'fg bg: ' , fg , bg ) ;
			
			fg = fgCursorTable[ fg ] ;
			bg = bgCursorTable[ bg ] ;
			
			return string.format( '\x1b[?16;%u;%uc' , fg , bg * 16 ) ;
		}
	} ,
	
	// It doesn't support RGB, but we can choose an ANSI color close to it
	setCursorColorRgb: {
		on: '%[setCursorColorRgb:%a%a%a]' ,
		handler: function setCursorColorRgb( r , g , b ) {
			
			if ( typeof r !== 'number' || typeof g !== 'number' || typeof b !== 'number' ) { return '' ; }
			
			r = Math.floor( r ) ;
			g = Math.floor( g ) ;
			b = Math.floor( b ) ;
			
			if ( r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 ) { return '' ; }
			
			var register = this.root.registerForRgb( r , g , b , 0 , 15 ) ;
			
			//console.log( 'Register:' , register ) ;
			
			return this.root.str.setCursorColor( register , 0 ) ;
		}
	} ,
	
	/*
		This part is a bit of a nasty hack: originally, escape sequence should produce... well... an escape sequence...
		Here an empty string is returned, but some underlying actions are performed.
		This is because the "Linux Console" terminal does not support the mouse, so nothing should be sent to it,
		however we will try to connect to the GPM daemon if it exists.
		It is not very clean, ideally this should be an advanced (not chainable) feature, but doing so would break
		compatibility with other terminal driver.
	*/
	
	// Mouse 'button' mode
	mouseButton: {
		on: '%[mouseButton]' ,
		off: '%[mouseButton]' ,
		handler: function mouseButton() { gpmMouse.call( this , 'button' ) ; return '' ; } ,
		offHandler: function mouseButton() { gpmMouse.call( this , false ) ; return '' ; }
	} ,
	
	// Mouse 'drag' mode
	mouseDrag: {
		on: '%[mouseDrag]' ,
		off: '%[mouseDrag]' ,
		handler: function mouseDrag() { gpmMouse.call( this , 'drag' ) ; return '' ; } ,
		offHandler: function mouseDrag() { gpmMouse.call( this , false ) ; return '' ; }
	} ,
	
	// Mouse 'motion' mode
	mouseMotion: {
		on: '%[mouseMotion]' ,
		off: '%[mouseMotion]' ,
		handler: function mouseMotion() { gpmMouse.call( this , 'motion' ) ; return '' ; } ,
		offHandler: function mouseMotion() { gpmMouse.call( this , false ) ; return '' ; }
	} ,
	
	mouseHilight: { on: '' , off: '' } ,
	mouseSGR: { on: '' , off: '' } ,
	focusEvent: { on: '' , off: '' }
} ) ;
Beispiel #9
0

var tree = require( 'tree-kit' ) ;
var xterm256 = require( './xterm-256color.js' ) ;
var gnome = require( './gnome.js' ) ;



// Remove colors
var defaultColor = '\x1b[39m' ; // back to the default color, most of time it is the same than .white
var bgDefaultColor = '\x1b[49m' ;   // back to the default color, most of time it is the same than .bgBlack


var	esc = tree.extend( { own: true } , Object.create( xterm256.esc ) , gnome.esc , {

	color24bits: { on: '\x1b[38;2;%u;%u;%um' , off: defaultColor , optimized: ( r , g , b ) => '\x1b[38;2;' + r + ';' + g + ';' + b + 'm' } ,
	bgColor24bits: { on: '\x1b[48;2;%u;%u;%um' , off: bgDefaultColor , optimized: ( r , g , b ) => '\x1b[48;2;' + r + ';' + g + ';' + b + 'm' }
} ) ;


// So far, we derivate from xterm-256color and then just add specific things (owned properties)
// of gnome, thus we achieve a clean inheritance model without duplicated code.

module.exports = {
	esc: esc ,
	keymap: tree.extend( { own: true } , Object.create( xterm256.keymap ) , gnome.keymap ) ,
	handler: tree.extend( { own: true } , Object.create( xterm256.handler ) , gnome.handler ) ,
	support: {
		deltaEscapeSequence: true ,
		"256colors": true ,
		"24bitsColors": true ,	// DEPRECATED
Beispiel #10
0
var tree = require( 'tree-kit' ) ;
var xterm = require( './xterm.js' ) ;



var esc = tree.extend( null , Object.create( xterm.esc ) , {
	
	// Cursor styles
	
	// Looks like a no go, gnome-terminal is too stubborn to let the application decide about that
	blockCursor: { on: '' , na: true } ,
	blinkingBlockCursor: { on: '' , na: true } ,
	underlineCursor: { on: '' , na: true } ,
	blinkingUnderlineCursor: { on: '' , na: true } ,
	beamCursor: { on: '' , na: true } ,
	blinkingBeamCursor: { on: '' , na: true }
	
	/*
	blockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	blinkingBlockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	underlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	blinkingUnderlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	beamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
	blinkingBeamCursor: { on: '\x1b]50;CursorShape=1\x07' }
	*/
} ) ;




Beispiel #11
0


var tree = require( 'tree-kit' ) ;
var xterm = require( './xterm.js' ) ;



var esc = tree.extend( null , Object.create( xterm.esc ) , {

	// Cursor styles not supported
	blockCursor: { on: '' , na: true } ,
	blinkingBlockCursor: { on: '' , na: true } ,
	underlineCursor: { on: '' , na: true } ,
	blinkingUnderlineCursor: { on: '' , na: true } ,
	beamCursor: { on: '' , na: true } ,
	blinkingBeamCursor: { on: '' , na: true } ,

	// Not capable, fallback to mouseButton
	mouseDrag: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,
	mouseMotion: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,

	requestColor: { on: '%D' , na: true }	// not capable
} ) ;





/* Key Mapping */

Beispiel #12
0
// Fail-safe xterm-compatible

var esc = tree.extend( null , Object.create( xterm.esc ) , {
	
	// KDE Konsole does not support that. This workaround use up()/down() & column(1)
	nextLine: { on: '\x1b[%UB\x1b[1G' } ,
	previousLine: { on: '\x1b[%UA\x1b[1G' } ,
	
	// Cursor styles
	
	// Try that sequences for instance, if it fails gracefully, it will be kept
	// Xterm sequences fail and write garbage
	blockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	blinkingBlockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	underlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	blinkingUnderlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	beamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
	blinkingBeamCursor: { on: '\x1b]50;CursorShape=1\x07' }
	
	// Disabled version
	/*
	blockCursor: { on: '' } ,
	blinkingBlockCursor: { on: '' } ,
	underlineCursor: { on: '' } ,
	blinkingUnderlineCursor: { on: '' } ,
	beamCursor: { on: '' } ,
	blinkingBeamCursor: { on: '' }
	*/
} ) ;



// Remove colors
var defaultColor = '\x1b[39m' ; // back to the default color, most of time it is the same than .white
var bgDefaultColor = '\x1b[49m' ;   // back to the default color, most of time it is the same than .bgBlack



var esc = tree.extend( null , Object.create( xterm256.esc ) , {
	
	// 24 bits colors
	color24bits: { on: '\x1b[38;2;%u;%u;%um' , off: defaultColor } ,
	bgColor24bits: { on: '\x1b[48;2;%u;%u;%um' , off: bgDefaultColor } ,
	
	// Cursor styles not supported
	blockCursor: { on: '' , na: true } ,
	blinkingBlockCursor: { on: '' , na: true } ,
	underlineCursor: { on: '' , na: true } ,
	blinkingUnderlineCursor: { on: '' , na: true } ,
	beamCursor: { on: '' , na: true } ,
	blinkingBeamCursor: { on: '' , na: true }
} ) ;





var keymap = Object.create( xterm256.keymap ) ;
var handler = Object.create( xterm256.handler ) ;

Beispiel #14
0
var esc = tree.extend( null , Object.create( xterm.esc ) , {

	// Eterm doesn't have bright color code, they are produced using 'bold' (which is not bold, by the way...)
	defaultColor: { on: defaultColor } ,
	brightBlack: { on: bold + '\x1b[30m' , off: defaultColor } ,
	brightRed: { on: bold + '\x1b[31m' , off: defaultColor } ,
	brightGreen: { on: bold + '\x1b[32m' , off: defaultColor } ,
	brightYellow: { on: bold + '\x1b[33m' , off: defaultColor } ,
	brightBlue: { on: bold + '\x1b[34m' , off: defaultColor } ,
	brightMagenta: { on: bold + '\x1b[35m' , off: defaultColor } ,
	brightCyan: { on: bold + '\x1b[36m' , off: defaultColor } ,
	brightWhite: { on: bold + '\x1b[37m' , off: defaultColor } ,
	brightColor: { on: bold + '\x1b[3%um' , off: defaultColor } ,	// should be called with a 0..7 integer

	// Eterm console doesn't have bright bg color code, they are produced using 'blink' (which does not blink, by the way...)
	bgDefaultColor: { on: bgDefaultColor } ,
	bgBrightBlack: { on: blink + '\x1b[40m' , off: bgDefaultColor } ,
	bgBrightRed: { on: blink + '\x1b[41m' , off: bgDefaultColor } ,
	bgBrightGreen: { on: blink + '\x1b[42m' , off: bgDefaultColor } ,
	bgBrightYellow: { on: blink + '\x1b[43m' , off: bgDefaultColor } ,
	bgBrightBlue: { on: blink + '\x1b[44m' , off: bgDefaultColor } ,
	bgBrightMagenta: { on: blink + '\x1b[45m' , off: bgDefaultColor } ,
	bgBrightCyan: { on: blink + '\x1b[46m' , off: bgDefaultColor } ,
	bgBrightWhite: { on: blink + '\x1b[47m' , off: bgDefaultColor } ,
	bgBrightColor: { on: blink + '\x1b[4%um' , off: bgDefaultColor } ,	// should be called with a 0..7 integer

	// Cursor styles not supported
	blockCursor: { on: '' , na: true } ,
	blinkingBlockCursor: { on: '' , na: true } ,
	underlineCursor: { on: '' , na: true } ,
	blinkingUnderlineCursor: { on: '' , na: true } ,
	beamCursor: { on: '' , na: true } ,
	blinkingBeamCursor: { on: '' , na: true } ,

	// Not capable, fallback to mouseButton
	mouseDrag: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,
	mouseMotion: { on: '\x1b[?1000h' , off: '\x1b[?1000l' , fb: true } ,

	requestColor: { on: '%D' , na: true }	// not capable
} ) ;
Beispiel #15
0


var termkit = {} ;
module.exports = termkit ;



// Load submodules in the termkit tree
termkit.tty = require( './tty.js' ) ;

// For some reason, starting from node v4, once process.stdin getter is triggered, the 'tty' command does not work.
// This 'hack' cache the result of the command 'tty' if we are in the linux console, so 'gpm' can work.
if ( process.env.TERM === 'linux' ) { termkit.tty.getPath() ; }

tree.extend( null , termkit , require( './misc.js' ) ) ;
tree.extend( null , termkit , require( './detectTerminal.js' ) ) ;

termkit.Rect = require( './Rect.js' ) ;
termkit.ScreenBuffer = require( './ScreenBuffer.js' ) ;
termkit.TextBuffer = require( './TextBuffer.js' ) ;
termkit.autoComplete = require( './autoComplete.js' ) ;
termkit.spChars = require( './spChars.js' ) ;

termkit.Terminal = require( './Terminal.js' ) ;
termkit.createTerminal = termkit.Terminal.create ;

// Lazy loading?
termkit.Element = require( './document/Element.js' ) ;
termkit.Document = require( './document/Document.js' ) ;
termkit.Container = require( './document/Container.js' ) ;
Beispiel #16
0

var tree = require( 'tree-kit' ) ;
var xterm = require( './xterm.js' ) ;



var esc = tree.extend( null , Object.create( xterm.esc ) , {
	
	// Amazingly, those uber-standard and uber-common sequences are *NOT* supported by Konsole...
	// SHAME on you KDE! Even the Linux Console support it!
	// This workaround use up()/down() & column(1)
	nextLine: { on: '\x1b[%UB\x1b[1G' } ,
	previousLine: { on: '\x1b[%UA\x1b[1G' } ,
	
	// Cursor styles
	blockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	blinkingBlockCursor: { on: '\x1b]50;CursorShape=0\x07' } ,
	underlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	blinkingUnderlineCursor: { on: '\x1b]50;CursorShape=2\x07' } ,
	beamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
	blinkingBeamCursor: { on: '\x1b]50;CursorShape=1\x07' } ,
	
	requestColor: { on: '%D' , na: true }	// not capable
} ) ;





			/* Key Mapping */
Beispiel #17
0
	errorStackLine: inspectStyleNoop ,
	errorStackColumn: inspectStyleNoop
} ;



inspectStyle.color = tree.extend( null , {} , inspectStyle.none , {
	limit: function( str ) { return ansi.bold + ansi.brightRed + str + ansi.reset ; } ,
	type: function( str ) { return ansi.italic + ansi.brightBlack + str + ansi.reset ; } ,
	constant: function( str ) { return ansi.cyan + str + ansi.reset ; } ,
	funcName: function( str ) { return ansi.italic + ansi.magenta + str + ansi.reset ; } ,
	constructorName: function( str ) { return ansi.magenta + str + ansi.reset ; } ,
	length: function( str ) { return ansi.italic + ansi.brightBlack + str + ansi.reset ; } ,
	key: function( str ) { return ansi.green + str + ansi.reset ; } ,
	index: function( str ) { return ansi.blue + str + ansi.reset ; } ,
	number: function( str ) { return ansi.cyan + str + ansi.reset ; } ,
	inspect: function( str ) { return ansi.cyan + str + ansi.reset ; } ,
	string: function( str ) { return ansi.blue + str + ansi.reset ; } ,
	errorType: function( str ) { return ansi.red + ansi.bold + str + ansi.reset ; } ,
	errorMessage: function( str ) { return ansi.red + ansi.italic + str + ansi.reset ; } ,
	errorStack: function( str ) { return ansi.brightBlack + str + ansi.reset ; } ,
	errorStackMethod: function( str ) { return ansi.brightYellow + str + ansi.reset ; } ,
	errorStackFile: function( str ) { return ansi.brightCyan + str + ansi.reset ; } ,
	errorStackLine: function( str ) { return ansi.blue + str + ansi.reset ; } ,
	errorStackColumn: function( str ) { return ansi.magenta + str + ansi.reset ; }
} ) ;



inspectStyle.html = tree.extend( null , {} , inspectStyle.none , {
	tab: '&nbsp;&nbsp;&nbsp;&nbsp;' ,
	nl: '<br />' ,
Beispiel #18
0
	SOFTWARE.
*/



var tree = require( 'tree-kit' ) ;
var xterm256 = require( './xterm-256color.js' ) ;



var esc = tree.extend( null , Object.create( xterm256.esc ) , {
	
	// Cursor styles
	
	// Cursor styles not supported
	blockCursor: { on: '' , na: true } ,
	blinkingBlockCursor: { on: '' , na: true } ,
	underlineCursor: { on: '' , na: true } ,
	blinkingUnderlineCursor: { on: '' , na: true } ,
	beamCursor: { on: '' , na: true } ,
	blinkingBeamCursor: { on: '' , na: true }
} ) ;





var keymap = Object.create( xterm256.keymap ) ;
var handler = Object.create( xterm256.handler ) ;


	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.
*/



var tree = require( 'tree-kit' ) ;
var xterm256 = require( './xterm-256color.js' ) ;
var xtermGeneric = require( './xterm.generic.js' ) ;



// Fail-safe xterm-compatible.

// So far, we derivate from xterm-256color and then just add specific things (owned properties)
// of xterm.generic.js, thus we achieve a clean inheritance model without duplicated code.

module.exports = {
	esc: tree.extend( { own: true } , Object.create( xterm256.esc ) , xtermGeneric.esc ) ,
	keymap: tree.extend( { own: true } , Object.create( xterm256.keymap ) , xtermGeneric.keymap ) ,
	handler: tree.extend( { own: true } , Object.create( xterm256.handler ) , xtermGeneric.handler ) ,
	colorRegister: require( '../colorScheme/vga.json' )
} ;