forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cs
More file actions
94 lines (76 loc) · 3.16 KB
/
Console.cs
File metadata and controls
94 lines (76 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting.Hosting.Providers;
using Microsoft.Scripting.Hosting.Shell;
using IronPython.Hosting;
using IronPython.Runtime;
internal sealed class PythonConsoleHost : ConsoleHost {
protected override Type Provider {
get { return typeof(PythonContext); }
}
protected override CommandLine/*!*/ CreateCommandLine() {
return new PythonCommandLine();
}
protected override OptionsParser/*!*/ CreateOptionsParser() {
return new PythonOptionsParser();
}
protected override ScriptRuntimeSetup CreateRuntimeSetup() {
ScriptRuntimeSetup srs = base.CreateRuntimeSetup();
foreach (var langSetup in srs.LanguageSetups) {
if (langSetup.FileExtensions.Contains(".py")) {
langSetup.Options["SearchPaths"] = new string[0];
}
}
return srs;
}
protected override LanguageSetup CreateLanguageSetup() {
return Python.CreateLanguageSetup(null);
}
protected override IConsole CreateConsole(ScriptEngine engine, CommandLine commandLine, ConsoleOptions options) {
PythonConsoleOptions pyoptions = (PythonConsoleOptions)options;
return pyoptions.BasicConsole ? new BasicConsole(options.ColorfulConsole) : new SuperConsole(commandLine, options.ColorfulConsole);
}
protected override void ParseHostOptions(string/*!*/[]/*!*/ args) {
// Python doesn't want any of the DLR base options.
foreach (string s in args) {
Options.IgnoredArgs.Add(s);
}
}
protected override void ExecuteInternal() {
var pc = HostingHelpers.GetLanguageContext(Engine) as PythonContext;
pc.SetModuleState(typeof(ScriptEngine), Engine);
base.ExecuteInternal();
}
#if DEBUG
private static string[] MaybeAttachDebugger(string[] args) {
int attachDebugger = Array.IndexOf(args, "-X:Attach");
if (attachDebugger != -1) {
// Remove -X:Attach from the arg list, since after this point it's no use
string[] newArgs = new string[args.Length - 1];
Array.Copy(args, newArgs, attachDebugger);
Array.Copy(args, attachDebugger + 1, newArgs, attachDebugger, newArgs.Length - attachDebugger);
args = newArgs;
// Launch a debugger. This seems to be more reliable than
// Debugger.Break().
if (Debugger.IsAttached == false) Debugger.Launch();
}
return args;
}
#endif
[STAThread]
public static int Main(string[] args) {
// Work around issue w/ pydoc - piping to more doesn't work so
// instead indicate that we're a dumb terminal
if (Environment.GetEnvironmentVariable("TERM") == null) {
Environment.SetEnvironmentVariable("TERM", "dumb");
}
#if DEBUG
args = MaybeAttachDebugger(args);
#endif
return new PythonConsoleHost().Run(args);
}
}