Prompt Toolkit 2 History Object (xonsh.ptk2.history)

History object for use with prompt_toolkit.

class xonsh.ptk2.history.PromptToolkitHistory(load_prev=True, *args, **kwargs)[source]

History class that implements the prompt-toolkit history interface with the xonsh backend.

Initialize history object.

append_string(self, string:str) → None

Add string to the history.

get_strings(self) → List[str]

Get the strings from the history that are loaded so far.

load(self, item_loaded_callback:Callable[[str], NoneType]) → 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 History object as well as the start of the loading happens before is called, and it can continue even after 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, 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_string(self, entry)[source]

Store the string in persistent storage.