Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nitx.nit
index 061b44e..7162e43 100644 (file)
@@ -25,7 +25,7 @@ module nitx
 
 import frontend
 import doc::term
-import readline
+import prompt
 
 redef class ToolContext
 
@@ -43,8 +43,11 @@ end
 # Using `prompt`, the command line can be turned on an interactive tool.
 class Nitx
 
-       # ModelView that contains the informations to display
-       var view: ModelView
+       # 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
@@ -66,7 +69,7 @@ class Nitx
                print "Welcome in the Nit Index!"
                print ""
                print "Loaded packages:\n"
-               var cmd = new CmdModelEntities(view, kind = "packages")
+               var cmd = new CmdModelEntities(model, kind = "packages")
                cmd.init_command
                for mpackage in cmd.results.as(not null) do
                        print " * {mpackage.full_name}"
@@ -90,15 +93,18 @@ class Nitx
 
        # Prompts the user for a query.
        fun prompt do
-               var line = readline(">> ", true)
+               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(view, modelbuilder, catalog) is lazy
+       var parser = new CommandParser(model, mainmodule, modelbuilder, catalog) is lazy
 
        # Processes the query string and performs it.
        fun do_command(str: String) do
@@ -114,24 +120,15 @@ end
 
 redef class Catalog
        # Build the catalog for Nitx
-       private fun build_catalog(view: ModelView) do
-               # Compute the poset
-               for p in view.mpackages do
+       private fun build_catalog(model: Model, filter: nullable ModelFilter) do
+               # Scan all modules of collected packages
+               for p in model.collect_mpackages(filter) do
                        var g = p.root
                        assert g != null
                        modelbuilder.scan_group(g)
-
-                       deps.add_node(p)
-                       for gg in p.mgroups do for m in gg.mmodules do
-                               for im in m.in_importation.direct_greaters do
-                                       var ip = im.mpackage
-                                       if ip == null or ip == p then continue
-                                       deps.add_edge(p, ip)
-                               end
-                       end
                end
                # Build the catalog
-               for mpackage in view.mpackages do
+               for mpackage in model.collect_mpackages(filter) do
                        package_page(mpackage)
                        git_info(mpackage)
                        mpackage_stats(mpackage)
@@ -162,15 +159,14 @@ toolcontext.run_global_phases(mmodules)
 var mainmodule = toolcontext.make_main_module(mmodules)
 
 # build views
-var view = new ModelView(model, mainmodule)
 var catalog = null
 if toolcontext.opt_catalog.value then
        catalog = new Catalog(mbuilder)
-       catalog.build_catalog(view)
+       catalog.build_catalog(model)
 end
 
 # start nitx
-var nitx = new Nitx(view, mbuilder, catalog, toolcontext.opt_no_color.value)
+var nitx = new Nitx(model, mainmodule, mbuilder, catalog, toolcontext.opt_no_color.value)
 var q = toolcontext.opt_command.value
 if q != null then # shortcut prompt
        print ""