Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History export / import to file #35

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ollbx
Copy link
Contributor

@ollbx ollbx commented Nov 28, 2024

This pull requests extends the history API slightly, to allow for the import and export of the history to a file. Detailed changes:

  • Removed the mpsc channel for the history. This also gets rid of the futures-channel dependency of the crate itself.
  • Added test code to the history (mainly to ensure that I didn't screw it up the refactor).
  • Reversed the order of items in the history VecDeque, so that entries are ordered oldest-to-newest (more natural for the API).
  • Slight change: when changing the history size, the history position is now reset. The old code left the position alone, so it could end up beyond the length of the history. Probably not critical, but I felt that resetting the history position seems reasonable here.
  • Added functions in Readline:
    • get_history_entries() ... provides access to the internal VecDeque.
    • set_history_entries() ... allows for replacing the history contents.
    • clear_history()
    • save_history() ... saves the history to a plain text file
    • load_history() ... loads the history from a plain text file

Debatable API decisions:

  • set_history_entries() will accept any impl IntoIterator<Item = String>. I didn't want to force users to use a VecDeque, but I could also change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant