prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.28k stars 715 forks source link

Integrate IPython with prompt toolkit issue #992

Open zsaladin opened 4 years ago

zsaladin commented 4 years ago

I am trying to embed IPython into my app using prompt toolkit. I'd like to put IPython shell bottom of HSplit Container.

Here's an example app layout.

--------------------------------------------------
(TextArea, multiline, scroll)
Log1
Log2
Log3
--------------------------------------------------
(IPython Shell, multiline, scroll)
In [1] : 1 + 1
Out [1] : 2
--------------------------------------------------

But I have hard time to do it.

First, IPython uses prompt. It calls Application.run() internally and uses its own layout. So it is difficult to use it with my prompt toolkit application.

Second IPython calls prompt repeatedly. I manipulated shell.pt_app.layout.container. So the layout could be changed. But after typing enter key, the whole layout was drawn again. The reason is that prompt redraws whole containers and is always called after completing input.

Could you advise for it?

jonathanslenders commented 4 years ago

Hi @zsaladin,

Easiest is probably to use a ptterm widget in your application to emulate a full terminal and run IPython in there. IPython is not meant to be embedded in another application like this.

Otherwise, maybe check this example: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/examples/full-screen/calculator.py

See: https://github.com/prompt-toolkit/ptterm

Hope that helps.