Unfortunately there's currently no way to switch this from Python code.
What we need to do is expose something in IronPythonConsole.exe which lets you
set PythonCommandLine.MyConsole (currently you can't do this because
PythonCommandLine is private). If you made PythonCommandLine public you could
do clr.AddReference('IronPythonConsole.exe') and then from IronPythonConsole
import PythonCommandLine, IConsole. Finally you can implement your own console:
class MyConsole(IConsole):
def ReadLine(autoIndentSize): pass
def Write(text, style): pass
def WriteLine(text, style): pass
and then call PythonCommandLine.MyConsole = MyConsole()
and those methods will override the interface implementation (or in other words
- it's quite easy to deal with overriding methods :) ).
That's the hacky way to get to where you can start experimenting with this. We
probably need to come up w/ a better long-term way to do this. This is an
unfortunate side effect of the runtime & console being so separated - the
runtime doesn't know anything about the console, and the console can't use the
runtime's stdin because it needs to be able to deal w/ input such as arrow keys.
I don't know that we could do anything here before 1.0, but I'll open a
CodePlex bug for improving console <-> runtime interop.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jörgen Stenarson
Sent: Thursday, June 29, 2006 12:14 PM
To: Discussion of IronPython
Subject: Re: [IronPython] ironpython alternative to PyOS_ReadlineFunctionPointer
Dino,
I've been sucessful in locating ReadLineFromSrc but not IConsole (from the
IronPythonConsole). However ReadLineFromSrc is a read only attribute in the
IronPython.Runtime.Operations.Ops module. Ideally I would like to do something
like this:
import IronPython
def my_readline():
txt=System.Console.ReadLine()
return txt
IronPython.readline=my_readline
But I guess it could be difficult if what I want to override a method in a
class instance written in C#. Am I right? Could this be changed in that case?
/Jörgen
Dino Viehland skrev:
> Ops.ReadLineFromSrc will be called if for example someone calls raw_input()
> from Python (one way to read from the user). IConsole.ReadLine gets called
> when we're reading input from the console for some code you're typing in.
>
> I think ideally these would be using the same underlying implementation but
> do to the extra things our fancy console does they're rather divergent today.
> For readline I suspect you'll want to be updating IConsole.ReadLine instead.
>
> Also it'd be great if you could keep us updated when you get something
> working. One of our PMs has wanted good history support, and I think Bruce
> (who implemented socket as part of his internship this summer) might prefer
> readline's key bindings :).
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jörgen
> Stenarson
> Sent: Wednesday, June 28, 2006 2:21 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] ironpython alternative to
> PyOS_ReadlineFunctionPointer
>
> Thanks for the response, I will have to investigate this further.
>
> Just to clarify, what I want to do is replace the function that is called by
> the ironpython interpreter to read a line of text from the user.
>
> /Jörgen
>
> Dino Viehland skrev:
>> Is IronPython.Runtime.Operations.Ops.ReadLineFromSrc what you're looking
>> for? This allows you to read a line of input from std-in.
>>
>> I'm not familiar w/ CPython's internal interfaces so I'm not sure if that's
>> right or not... The other option is that this is the functionality that
>> lives in the console, and you want IConsole.ReadLine.
>>
>> Currently these two are rather disconnected.
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Jörgen
>> Stenarson
>> Sent: Wednesday, June 28, 2006 11:44 AM
>> To: Discussion of IronPython
>> Subject: [IronPython] ironpython alternative to
>> PyOS_ReadlineFunctionPointer
>>
>> Hi,
>>
>> I'm working on a python based implementation of readline (pyreadline
>> available from
>> http://projects.scipy.org/ipython/ipython/wiki/PyReadline/Intro). I'm
>> experimenting with adding support for ironpython, I have been successful in
>> porting some of the ctypes based routines used for keyboard event processing
>> to ironpython using System.Console. It has been quite painless so far.
>>
>> But to take this further I need to know the ironpython equivalent to
>> PyOS_ReadlineFunctionPointer in cpython and how to use it. Is this
>> functionality exposed and if not do you plan to expose it?
>>
>> Best regards,
>> Jörgen Stenarson
>>
>> _______________________________________________
>> users mailing list
>> [email protected]
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> _______________________________________________
>> users mailing list
>> [email protected]
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com