core: move more servies to Text (receiver and args only)
[nit.git] / contrib / nitin / nitin.nit
index 0d4484d..9e75b28 100644 (file)
@@ -24,6 +24,15 @@ import nitc::frontend
 import nitc::parser_util
 
 redef class ToolContext
+
+       # --no-prompt
+       var opt_no_prompt = new OptionBool("Disable writing a prompt.", "--no-prompt")
+
+       redef init do
+               super
+               option_context.add_option(opt_no_prompt)
+       end
+
        # Parse a full module given as a string
        #
        # Return a AModule or a AError
@@ -62,7 +71,13 @@ redef class ToolContext
                var oldtext = ""
 
                loop
-                       var s = readline(prompt)
+                       var s
+                       if opt_no_prompt.value then
+                               s = stdin.read_line
+                               if s == "" and stdin.eof then s = null
+                       else
+                               s = readline(prompt)
+                       end
                        if s == null then return null
                        if s == "" then continue
 
@@ -169,6 +184,21 @@ loop
 
        # Run the main if the AST contains a main
        if amodule.n_classdefs.not_empty and amodule.n_classdefs.last isa AMainClassdef then
-               interpreter.send(mainprop, [mainobj])
+               do
+                       interpreter.catch_count += 1
+                       interpreter.send(mainprop, [mainobj])
+               catch
+                       var e = interpreter.last_error
+                       if e != null then
+                               var en = e.node
+                               if en != null then
+                                       print "{en.location}: Runtime error: {e.message}\n{en.location.colored_line("0;31")}"
+                               else
+                                       print "Runtime error: {e.message}"
+                               end
+                       end
+                       print interpreter.stack_trace
+                       interpreter.frames.clear
+               end
        end
 end