Prompt Toolkit 2+ History Object (
History object for use with prompt_toolkit.
PromptToolkitHistory(load_prev=True, *args, **kwargs)¶
History class that implements the prompt-toolkit history interface with the xonsh backend.
Initialize history object.
append_string(string: str) → None¶
Add string to the history.
get_strings() → List[str]¶
Get the strings from the history that are loaded so far.
load(item_loaded_callback: Callable[str, None]) → None¶
Load the history and call the callback for every entry in the history.
- XXX: The callback can be called from another thread, which happens in
case of ThreadedHistory.
We can’t assume that an asyncio event loop is running, and schedule the insertion into the Buffer using the event loop.
The reason is that the creation of the
Historyobject as well as the start of the loading happens before Application.run() is called, and it can continue even after Application.run() terminates. (Which is useful to have a complete history during the next prompt.)
Calling get_event_loop() right here is also not guaranteed to return the same event loop which is used in Application.run, because a new event loop can be created during the run. This is useful in Python REPLs, where we want to use one event loop for the prompt, and have another one active during the eval of the commands. (Otherwise, the user can schedule a while/true loop and freeze the UI.)
Loads synchronous history strings
Store the string in persistent storage.