hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.53k stars 149 forks source link

rlwrap modifies a line after entering #178

Closed ser-vasilich closed 1 year ago

ser-vasilich commented 1 year ago

I have a simple program in Rust that prints a prompt, reads a string, and prints it. read1line.rs

use std::io::{self, BufRead};
use std::io::Write;

fn main() {
    print!("prompt>");
    let _ = io::stdout().lock().flush();
    let stdin = io::stdin();
    let line = stdin.lock().lines().next().unwrap().unwrap();
    println!("{}",line);
}

When I run the program in terminal and enter line 123, I get the result:

->rustc read1line.rs
->./read1line
prompt>123
123

The result of running in terminal on MacOS with rlwrap:

->uname -v
Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64

->rlwrap ./rea1line
prompt>123    123
123

The result of running in terminal on Ubuntu with rlwrap:

->uname -av
Linux serhii-desktop 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

->rlwrap ./read1line
123
123

On Linux, the prompt disappears, and on MacOS, there is an extra text as long as the prompt.

hanslub42 commented 1 year ago

Because rlwrap has to rely on undocumented (and changing) readline behaviour (like the positioning of the cursor right after accepting a line) there have been some problems with bracketed paste mode (which have become much more widespread after readline started enabling this mode by default)

Your Ubuntu problem is a duplicate of #108, your MacOS problem is a duplicate of #168.

To avoid problems, either use the newest readline and rlwrap, or disabe bracketed-paste by putting ...

 set enable-bracketed-paste off

... somewhere in ~/.inputrc