PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_2_0/Src/IronPythonConsole/Console.cs

#
C# | 76 lines | 46 code | 13 blank | 17 comment | 4 complexity | 5776adeb54477c2608af8d2c65bc2b4c MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Microsoft Public License, please send an email to 
 8 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Microsoft Public License.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16using System; using Microsoft;
17using System.Text;
18using IronPython.Hosting;
19using IronPython.Runtime;
20using Microsoft.Scripting.Hosting;
21using Microsoft.Scripting.Hosting.Shell;
22using Microsoft.Scripting.Utils;
23using System.Diagnostics;
24using System.Reflection.Emit;
25
26internal sealed class PythonConsoleHost : ConsoleHost {
27
28    protected override Type Provider {
29        get { return typeof(PythonContext); }
30    }
31
32    protected override CommandLine/*!*/ CreateCommandLine() {
33        return new PythonCommandLine();
34    }
35
36    protected override OptionsParser/*!*/ CreateOptionsParser() {
37        return new PythonOptionsParser();
38    }
39
40    protected override LanguageSetup/*!*/ CreateLanguageSetup() {
41        return Python.CreateLanguageSetup(null);
42    }
43
44    protected override string/*!*/ GetHelp() {
45        StringBuilder sb = new StringBuilder();
46
47        sb.AppendLine(PythonCommandLine.GetLogoDisplay());
48        PrintLanguageHelp(sb);
49        sb.AppendLine();
50
51        return sb.ToString();
52    }
53
54    protected override void ParseHostOptions(string/*!*/[]/*!*/ args) {
55        // Python doesn't want any of the DLR base options.
56        foreach (string s in args) {
57            Options.IgnoredArgs.Add(s);
58        }
59    }
60
61    [STAThread]
62    public static int Main(string[] args) {
63        // Work around issue w/ pydoc - piping to more doesn't work so
64        // instead indicate that we're a dumb terminal
65        if (Environment.GetEnvironmentVariable("TERM") == null) {
66            Environment.SetEnvironmentVariable("TERM", "dumb");
67        }
68
69        if (typeof(DynamicMethod).GetConstructor(new Type[] { typeof(string), typeof(Type), typeof(Type[]), typeof(bool) }) == null) {
70            Console.WriteLine("IronPython requires .NET 2.0 SP1 or later to run.");
71            Environment.Exit(1);
72        }
73
74        return new PythonConsoleHost().Run(args);
75    }
76}