kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.54k stars 176 forks source link

fix: bracketed paste multiline accept only one line #758

Closed SalHe closed 5 months ago

SalHe commented 9 months ago

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 commented 9 months ago

See #690

gwenn commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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);. https://github.com/kkawakam/rustyline/issues/480#issuecomment-759759109

gwenn commented 9 months ago

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

gwenn commented 8 months ago

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

SalHe commented 5 months ago

@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.