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

Create something like `prompt_toolkit.readline`. #440

Open jonathanslenders opened 7 years ago

jonathanslenders commented 7 years ago

Deprecate prompt_toolkit.shortcuts and create an improved API instead. (However, don't remove the shortcuts module, there are too many people using it.)

The reason is that right now, we are missing some "state" between multiple calls of "prompt()". for instance, we loose the search history between two calls. But also, "operate-and-get-next" can't work without keeping some state in between "prompt()" calls.

I propose to build a new API like this:

from prompt_toolkit.text_input import create_session
session = create_session(...)
session.prompt('> ')
session.prompt('> ')

prompt()  # Call prompt from the system wide session.
stephenrauch commented 7 years ago

Will these calls to prompt return the entered string as usual?

jonathanslenders commented 7 years ago

Yes. That's the idea. But further, an API similar to what we have right now, that doesn't create such a session should remain. In that case, I'll use a global "session" object. This is what readline does as well, and it's similar to how the "requests" library create HTTP sessions.