Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: implement history #35

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

feat: implement history #35

wants to merge 7 commits into from

Conversation

NTBBloodbath
Copy link
Contributor

This PR aims to re-implement history saving, closing #23 by implementing last missing feature on that issue.

These changes are still in a very early stage, currently we are capable of creating history file (it is being created at data directory and is named neosh_history, e.g. this is the path in *nix systems: ~/.local/share/neosh/neosh_history) and saving it.

We are saving everything we can right now, that means we are saving built-in commands history with their exit codes (some of them are hard-coded to 0 at the moment due to their nature, e.g. echo or pwd), Lua chunks (NeoSH stdlib, Lua stdlib, functions, variables declaration, etc) and failed Lua commands.

Missing functionalities to be added before merging:

  • Refact history::get to return a vector with each history line instead of returning history as a string (this can be really hard for Lua chunks with incomplete input like functions in multiple lines).
  • Implement Up and Down arrow keys in src/core/input.rs to browse history, where Up gets previous history entry and Down gets the next one, like BASH or ZSH.

Notes:

  1. Second missing functionality task can also include Page Up and Page Down keys to do the same thing as the Up and Down arrow keys like in ZSH.
  2. As we discussed in our discord server, we want to make a smart history system that does not save commands that had a typo and stuff like that, however, this PR will cover only the core functionality and that logic will be implemented in another PR.

- Raise an error if directory does not exist
- Raise an error if path exists but it is not a directory
- History file syntax is the following: `exit_code: command`

TODO: add `Up` and `Down` arrows in `core/input.rs` to browse history
* main:
  chore(input): format, add data type to `buffer_len` declaration in `End` key body
  feat(input): add `Home` and `End` keys
@NTBBloodbath NTBBloodbath added the scope: enhancement New feature or request label Mar 30, 2022
@NTBBloodbath NTBBloodbath requested a review from n-shift March 30, 2022 22:28
@NTBBloodbath NTBBloodbath linked an issue Mar 30, 2022 that may be closed by this pull request
7 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
scope: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get functionality we had in rustyline in tui and crossterm
2 participants