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

fix: bracketed paste multiline accept only one line #758

Closed
wants to merge 1 commit into from

Conversation

SalHe
Copy link

@SalHe SalHe commented Jan 5, 2024

https://github.com/SalHe/rustyline/blob/e001cab7a04c36f2a113ef465325feb4c0d77f7b/src/lib.rs#L707

RawReader has been created and dropped when finished readline_edit.
BufReader has capacity 1024, so it might read more than readline_edit consumed (submitted when encouterred '\r').

For example,

1
2

has been pasted. The buffer reads "\033[220~1\r2\r\033[221~\000".
When accepted '\r', command has been submitted.

After this, we cannot retrieve rest of pasted command.
So '2\r\033[221~\000' has been ignored.

@gwenn gwenn added the invalid label Jan 5, 2024
@gwenn
Copy link
Collaborator

gwenn commented Jan 5, 2024

See #690

@gwenn
Copy link
Collaborator

gwenn commented Jan 5, 2024

Cannot reproduce locally:

% cargo run --example minimal
> line1
line2
line3
line4
line5
Line: line1
line2
line3
line4
line5
>

I tried with unix, mac, dos file content

@SalHe
Copy link
Author

SalHe commented Jan 6, 2024

Cannot reproduce locally:

% cargo run --example minimal
> line1
line2
line3
line4
line5
Line: line1
line2
line3
line4
line5
>

I tried with unix, mac, dos file content

Sorry I forgot to note that: rl.bind_sequence(KeyEvent(KeyCode::BracketedPasteStart, Modifiers::NONE), Cmd::Noop); should be configured.

use rustyline::{DefaultEditor, Result, Cmd, Modifiers, KeyCode, KeyEvent};

/// Minimal REPL
fn main() -> Result<()> {
    env_logger::init();
    let mut rl = DefaultEditor::new()?;
    rl.bind_sequence(KeyEvent(KeyCode::BracketedPasteStart, Modifiers::NONE), Cmd::Noop);
    loop {
        let line = rl.readline("> ")?; // read
        println!("Line: {line}"); // eval / print
    } // loop
}

In this case, pasted content should be accepted line by line. But now only the first line accepted.

@SalHe
Copy link
Author

SalHe commented Jan 6, 2024

It's a similar problem as #690 but without difference.
#690 solved lines sent to pty, but didn't solve rl.bind_sequence(KeyEvent(KeyCode::BracketedPasteStart, Modifiers::NONE), Cmd::Noop);. #480 (comment)

@gwenn
Copy link
Collaborator

gwenn commented Jan 6, 2024

Sorry but your PR is fixing an edge case while impacting the common case.

@gwenn
Copy link
Collaborator

gwenn commented Jan 21, 2024

@SalHe could you please try #761 ?
Or just disable bracketed paster

@SalHe
Copy link
Author

SalHe commented Apr 17, 2024

@SalHe could you please try #761 ? Or just disable bracketed paster

Sorry for reply lately due to working stuff.
I have tried the latest rustyline with feature buffer-redux it does solve this problem. That's so great!
Thanks for your work.

@SalHe SalHe closed this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants