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 doesn't seem to work for Readline #40

Closed
Tommypop2 opened this issue Dec 10, 2024 · 1 comment · Fixed by #49
Closed

History doesn't seem to work for Readline #40

Tommypop2 opened this issue Dec 10, 2024 · 1 comment · Fixed by #49

Comments

@Tommypop2
Copy link

Description

Using the arrows to navigate history doesn't work.

Reproduction

use promkit::{preset::readline::Readline, suggest::Suggest};

fn main() -> anyhow::Result<()> {
    let mut p = Readline::default()
        .enable_history()
        .enable_suggest(Suggest::from_iter([
            "apple",
            "applet",
            "application",
            "banana",
        ]))
        .prompt()?;
    loop {
        match p.run() {
            Ok(cmd) => {
                println!("result: {:?}", cmd);
            }
            Err(_) => {
                println!("Bye!");
                break;
            }
        }
    }
    Ok(())
}

Additional Info

When I try to log the history, it seems like the contents section is empty and doesn't get added to.
I tried adding the text entry manually to the history:

use promkit::{preset::readline::Readline, suggest::Suggest};

fn main() -> anyhow::Result<()> {
    let mut p = Readline::default()
        .enable_history()
        .enable_suggest(Suggest::from_iter([
            "apple",
            "applet",
            "application",
            "banana",
        ]))
        .prompt()?;
    loop {
        match p.run() {
            Ok(cmd) => {
                println!("result: {:?}", cmd);
                p.renderer
                    .text_editor_snapshot
                    .after_mut()
                    .history
                    .as_mut()
                    .unwrap()
                    .insert(cmd);
            }
            Err(_) => {
                println!("Bye!");
                break;
            }
        }
    }
    Ok(())
}

This worked for a single entry (I could press the up arrow once to get the previous command) but I couldn't go any further

@dalance
Copy link
Contributor

dalance commented Feb 18, 2025

I'm not the author, so this is just a guess, but it might be intentional.
By explicitly requesting history saving, you can customize which strings are saved and whether they are saved or not.
It might be useful to have an API like p.insert_history(cmd) because calling p.renderer...insert(cmd) is too long.

The issue with the history being cleared will be fixed in #49.

@ynqa ynqa closed this as completed in #49 Feb 19, 2025
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 a pull request may close this issue.

2 participants