Nitx handles console queries

Using prompt, the command line can be turned on an interactive tool.

Introduced properties

private var _catalog: nullable Catalog

nitc :: Nitx :: _catalog

Catalog if any
private var _mainmodule: MModule

nitc :: Nitx :: _mainmodule

Mainmodule for class linearization
private var _model: Model

nitc :: Nitx :: _model

Model that contains the informations to display
private var _modelbuilder: ModelBuilder

nitc :: Nitx :: _modelbuilder

ModelBuilder to access AST nodes
private var _no_color: Bool

nitc :: Nitx :: _no_color

Do not use colors in the output
private var _parser: CommandParser

nitc :: Nitx :: _parser

Parser used to process doc commands
fun catalog: nullable Catalog

nitc :: Nitx :: catalog

Catalog if any
protected fun catalog=(catalog: nullable Catalog)

nitc :: Nitx :: catalog=

Catalog if any
init defaultinit(model: Model, mainmodule: MModule, modelbuilder: ModelBuilder, catalog: nullable Catalog, no_color: nullable Bool)

nitc :: Nitx :: defaultinit

fun do_command(str: String)

nitc :: Nitx :: do_command

Processes the query string and performs it.
fun help

nitc :: Nitx :: help

Displays the list of available queries.
fun mainmodule: MModule

nitc :: Nitx :: mainmodule

Mainmodule for class linearization
protected fun mainmodule=(mainmodule: MModule)

nitc :: Nitx :: mainmodule=

Mainmodule for class linearization
fun model: Model

nitc :: Nitx :: model

Model that contains the informations to display
protected fun model=(model: Model)

nitc :: Nitx :: model=

Model that contains the informations to display
fun modelbuilder: ModelBuilder

nitc :: Nitx :: modelbuilder

ModelBuilder to access AST nodes
protected fun modelbuilder=(modelbuilder: ModelBuilder)

nitc :: Nitx :: modelbuilder=

ModelBuilder to access AST nodes
fun no_color: Bool

nitc :: Nitx :: no_color

Do not use colors in the output
protected fun no_color=(no_color: nullable Bool)

nitc :: Nitx :: no_color=

Do not use colors in the output
fun parser: CommandParser

nitc :: Nitx :: parser

Parser used to process doc commands
protected fun parser=(parser: CommandParser)

nitc :: Nitx :: parser=

Parser used to process doc commands
fun prompt

nitc :: Nitx :: prompt

Prompts the user for a query.
fun start

nitc :: Nitx :: start

Displays the welcome message and start prompt.
fun welcome

nitc :: Nitx :: welcome

Displays the welcome message and the list of loaded modules.

Redefined properties

redef type SELF: Nitx

nitc $ Nitx :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _catalog: nullable Catalog

nitc :: Nitx :: _catalog

Catalog if any
private var _mainmodule: MModule

nitc :: Nitx :: _mainmodule

Mainmodule for class linearization
private var _model: Model

nitc :: Nitx :: _model

Model that contains the informations to display
private var _modelbuilder: ModelBuilder

nitc :: Nitx :: _modelbuilder

ModelBuilder to access AST nodes
private var _no_color: Bool

nitc :: Nitx :: _no_color

Do not use colors in the output
private var _parser: CommandParser

nitc :: Nitx :: _parser

Parser used to process doc commands
fun catalog: nullable Catalog

nitc :: Nitx :: catalog

Catalog if any
protected fun catalog=(catalog: nullable Catalog)

nitc :: Nitx :: catalog=

Catalog if any
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(model: Model, mainmodule: MModule, modelbuilder: ModelBuilder, catalog: nullable Catalog, no_color: nullable Bool)

nitc :: Nitx :: defaultinit

fun do_command(str: String)

nitc :: Nitx :: do_command

Processes the query string and performs it.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun help

nitc :: Nitx :: help

Displays the list of available queries.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun mainmodule: MModule

nitc :: Nitx :: mainmodule

Mainmodule for class linearization
protected fun mainmodule=(mainmodule: MModule)

nitc :: Nitx :: mainmodule=

Mainmodule for class linearization
fun model: Model

nitc :: Nitx :: model

Model that contains the informations to display
protected fun model=(model: Model)

nitc :: Nitx :: model=

Model that contains the informations to display
fun modelbuilder: ModelBuilder

nitc :: Nitx :: modelbuilder

ModelBuilder to access AST nodes
protected fun modelbuilder=(modelbuilder: ModelBuilder)

nitc :: Nitx :: modelbuilder=

ModelBuilder to access AST nodes
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
fun no_color: Bool

nitc :: Nitx :: no_color

Do not use colors in the output
protected fun no_color=(no_color: nullable Bool)

nitc :: Nitx :: no_color=

Do not use colors in the output
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parser: CommandParser

nitc :: Nitx :: parser

Parser used to process doc commands
protected fun parser=(parser: CommandParser)

nitc :: Nitx :: parser=

Parser used to process doc commands
fun prompt

nitc :: Nitx :: prompt

Prompts the user for a query.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun start

nitc :: Nitx :: start

Displays the welcome message and start prompt.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun welcome

nitc :: Nitx :: welcome

Displays the welcome message and the list of loaded modules.
package_diagram nitc::Nitx Nitx core::Object Object nitc::Nitx->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitc $ Nitx
# Nitx handles console queries
#
# Using `prompt`, the command line can be turned on an interactive tool.
class Nitx

	# Model that contains the informations to display
	var model: Model

	# Mainmodule for class linearization
	var mainmodule: MModule

	# ModelBuilder to access AST nodes
	var modelbuilder: ModelBuilder

	# Catalog if any
	var catalog: nullable Catalog = null is optional

	# Do not use colors in the output
	var no_color = false is optional

	# Displays the welcome message and start prompt.
	fun start do
		welcome
		prompt
	end

	# Displays the welcome message and the list of loaded modules.
	fun welcome do
		print "Welcome in the Nit Index!"
		print ""
		print "Loaded packages:\n"
		var cmd = new CmdModelEntities(model, kind = "packages")
		cmd.init_command
		for mpackage in cmd.results.as(not null) do
			print " * {mpackage.full_name}"
		end
		help
	end

	# Displays the list of available queries.
	fun help do
		# TODO automatize that
		print "\nCommands:\n"
		for usage, doc in parser.commands_usage do
			var l = usage.length / 8
			print "\t{usage}{"\t" * (3 - l)}{doc}"
		end
		print "\n"
		print "\t:h\t\t\tdisplay this help message"
		print "\t:q\t\t\tquit interactive mode"
		print ""
	end

	# Prompts the user for a query.
	fun prompt do
		var line = sys.prompt(">> ", true)
		if line != null then
			do_command(line)
		else
			# EOF
			exit 0
		end
		prompt
	end

	# Parser used to process doc commands
	var parser = new CommandParser(model, mainmodule, modelbuilder, catalog) is lazy

	# Processes the query string and performs it.
	fun do_command(str: String) do
		if str == ":q" then
			exit 0
		else if str == ":h" then
			help
			return
		end
		parser.execute(str, no_color)
	end
end
src/nitx.nit:41,1--119,3