I've tried the obvious path in my pet open source project RevitPythonShell (a plugin for the building modeling software Autodesk Revit Architecture 2010): code.interact()
with the IronPython engine set up to use .NET streams for STDIN
and STDOUT
. These I then redirect to a TextBox
control. It kinda works, but really is only an ugly hack.
The main problem is getting all the shell stuff to work: Up-arrow and down-arrow for history, editing, copy & paste, EOF, syntax highlighting, tool tips etc. It takes a lot of work to get this right, and it is not really the problem I'm trying to solve (I'm trying to get an interactive shell hosted in Revit, not make the perfect shell GUI).
If this weren't a .NET project, I'd probably look into reusing PyCrust/PyWrap, but I'm not sure if that can be done from a WinForms project. Is there anything similar for .NET?
Has anyone ever implemented the IConsole
interface and can show an example of what I'd need to do? It seems this would be the proper route to go (as opposed to using the code
module), but for the life of me I can't figure it out. IronPython source code has no comments whatsoever.