Tom,
I think the problem is that on windows stdout is connected to the
console window which cannot interpret ansi color codes. Instead you need
to call a special function that does this for you. One way is to use
__IP.write to access the write method on the IPShell instance which does
this. I'm not sure what is the correct way to obtain this object.
def shortCutFunc(s):
__IP.write(sys.displayhook.prompt1.auto_rewrite()+ 'print %r\n'%s)
gives the desired behaviour when defined at the prompt.
/Jörgen
>> On windows this same code fails miserably because the escape sequences
> don't get translated properly to colors:
>> In [10]: def shortCutFunc(s):
> ....: sys.stdout.write(sys.displayhook.prompt1.auto_rewrite()+ 'print %r
> \n'%s)
> ....: print s
> ....: sys.stdout.write(sys.displayhook.prompt1.auto_rewrite()+ 'print repr(%
> r)\n'%s)
> ....: print repr(s)
> ....:
>> In [11]: shortCutFunc('s')
> ←[0;32m-------> ←[0mprint 's'
> s
> ←[0;32m-------> ←[0mprint repr('s')
> 's'
>>>> I suspect my sys.stdout.write is the problem but I don't know the
> correct cross platform alternative.
>>> Is this clear?
>>> On 9/17/07, Jörgen Stenarson <jorgen.stenarson@bostream.nu> wrote:
>> Tom,
>>>> can you provide a complete self contained example of what you are trying
>> to do? With a description of desired results. It would be helpful in
>> figuring out what goes wrong.
>>>> /Jörgen
>>>>> In particular, in this case I don't really know what the problem is on
>>> Win32, since I know very little about the handling of color escapes on
>>> that platform. I hope our resident win32 experts may be able to help.
>>>>>> Cheers,
>>>>>>>>> f
>>> _______________________________________________
>>> IPython-user mailing list
>>>IPython-user@scipy.org>>>http://lists.ipython.scipy.org/mailman/listinfo/ipython-user>>>>> _______________________________________________
>> IPython-user mailing list
>>IPython-user@scipy.org>>http://lists.ipython.scipy.org/mailman/listinfo/ipython-user>>