Sebastien Ros 11 лет назад
Родитель
Сommit
feaab23aa3
2 измененных файлов с 37 добавлено и 8 удалено
  1. 1 1
      Jint.Repl/Jint.Repl.csproj
  2. 36 7
      Jint.Repl/Program.cs

+ 1 - 1
Jint.Repl/Jint.Repl.csproj

@@ -8,7 +8,7 @@
     <OutputType>Exe</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Jint.Repl</RootNamespace>
-    <AssemblyName>Jint.Repl</AssemblyName>
+    <AssemblyName>jint</AssemblyName>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
   </PropertyGroup>

+ 36 - 7
Jint.Repl/Program.cs

@@ -1,5 +1,7 @@
 using System;
-using Jint.Native;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
 using Jint.Runtime;
 
 namespace Jint.Repl
@@ -9,13 +11,35 @@ namespace Jint.Repl
         static void Main(string[] args)
         {
             var engine = new Engine()
-                .SetValue("log", new Action<object>(Console.WriteLine))
+                .SetValue("print", new Action<object>(Console.WriteLine))
             ;
 
+            var filename = args.Length > 0 ? args[0] : "";
+            if (!String.IsNullOrEmpty(filename))
+            {
+                if (!File.Exists(filename))
+                {
+                    Console.WriteLine("Could not find file: {0}", filename);
+                }
+
+                var script = File.ReadAllText(filename);
+                var result = engine.GetValue(engine.Execute(script).GetCompletionValue());
+                return;
+            }
+
+            Assembly assembly = Assembly.GetExecutingAssembly();
+            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
+            string version = fvi.FileVersion;
+
+            Console.WriteLine("Welcome to Jint ({0})", version);
+            Console.WriteLine("Type 'exit' to leave, 'print()' to write on the console.");
+            Console.WriteLine();
+
+            var defaultColor = Console.ForegroundColor;
             while (true)
             {
-                Console.ForegroundColor = ConsoleColor.Green;
-                Console.Write(" > ");
+                Console.ForegroundColor = defaultColor;
+                Console.Write("jint> ");
                 var input = Console.ReadLine();
                 if (input == "exit")
                 {
@@ -25,15 +49,20 @@ namespace Jint.Repl
                 try
                 {
                     var result = engine.GetValue(engine.Execute(input).GetCompletionValue());
-                    var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, "  ")));
-                    Console.ForegroundColor = ConsoleColor.Magenta;
-                    Console.WriteLine("=> {0}", str);
+                    //var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, "  ")));
+                    //Console.ForegroundColor = ConsoleColor.Magenta;
+                    //Console.WriteLine("=> {0}", str);
                 }
                 catch (JavaScriptException je)
                 {
                     Console.ForegroundColor = ConsoleColor.Red;
                     Console.WriteLine(je.ToString());
                 }
+                catch (Exception e)
+                {
+                    Console.ForegroundColor = ConsoleColor.Red;
+                    Console.WriteLine(e.Message);
+                }
                 
             }
         }