IronPython Console Window Sample
This sample implements a console window that allows users to enter IronPython commands and execute them. The sample implements a Visual Studio service that exposes instances of the IronPython engine for use by the console window and any other application that needs to execute IronPython scripts.
Output from the commands is displayed in the console window. The console window hosts the IronPython Language Service Sample so that colorization and statement completion are available when typing commands.
Security Note |
|---|
| This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended. |
Here are the integration features highlighted by this sample:
-
The console window is a tool window that creates a TextBuffer object and hosts a TextView control that is initialized to use the text buffer.
-
The console window registers itself as a command filter and intercepts the key commands that it needs to handle, such as ENTER.
-
Command history is implemented using a class called HistoryBuffer that stores the list of commands executed inside the console, sorted by execution order.
-
The IronPython engine is exposed as a service, and can be used by other Visual Studio applications to execute IronPython scripts.
-
A reference to EnvDTE is added to the IronPython execution environment, giving IronPython scripts access to Visual Studio automation. You can develop an IronPython program by running short scripts from the console window, and then cutting and pasting the script into your program.
To build and run the sample
-
Open the IronPython.sln solution in the <Installation Path>\VisualStudioIntegration\Samples\IronPythonIntegration folder.
Note This sample includes the ConsoleWindow project, which contains an overview document with detailed implementation notes. To open it, right-click ConsoleWindow\Overview.xml, and then click View in Browser.
-
Press F5 to build the sample, register it in the experimental hive, and start Visual Studio from the experimental hive.
To see the sample's functionality
-
On the View menu, click Other Windows, and then click IronPython Console to display the console window.
-
Type2 + 2and press <Enter> to see the sum.
-
Typeprint "Hello"and press <Enter> to see "Hello". Notice that the keyword print and the string "Hello" are both colorized.
-
Press the UP ARROW and DOWN ARROW keys to run through the command history.
Demonstrates
| Classes | Interfaces |
|---|---|