Giter Club home page Giter Club logo

Comments (6)

gwenn avatar gwenn commented on August 29, 2024

I will try to reproduce.
Would you mind trying this setting: https://docs.rs/rustyline/latest/rustyline/config/enum.Behavior.html#variant.PreferTerm ?

    let config = Config::builder()
        .behavior(Behavior::PreferTerm)
        .build();
    let mut rl = DefaultEditor::with_config(config)?;

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Ok, I can reproduce.
Liner seems OK.
But not linenoise, replxx, ...
I tried with env_logger::init(); and export RUST_LOG=rustyline=debug but that didn't help.
It may be caused by the way we activate raw mode with TCSADRAIN here ?
I will try to investigate further...

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

Ok,
rustyline uses a BufReader.
And the whole input "1\n2\n" is read at once but only "1\n" is treated ("2\n" is discarded).

diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index 23bfcce..70e02f4 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -144,6 +144,7 @@ impl Read for TtyIn {
                     return Err(error);
                 }
             } else {
+                debug!(target: "rustyline", "read: {:?}", &buf[..res as usize]);
                 #[allow(clippy::cast_sign_loss)]
                 return Ok(res as usize);
             }
[DEBUG rustyline] read: [49, 10, 50, 10]

The BufReader is used for bracketed paste.
See https://en.wikipedia.org/wiki/Bracketed-paste
Maybe we should set the buffer size to 1 when bracketed paste is disabled ?

from rustyline.

gwenn avatar gwenn commented on August 29, 2024

With the following patch, I manage to fix the issue:

diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index 23bfcce..ff96dd6 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -229,8 +229,13 @@ impl PosixRawReader {
         key_map: PosixKeyMap,
         pipe_reader: Option<PipeReader>,
     ) -> Self {
+        let buffer_size = if config.enable_bracketed_paste() {
+            1024
+        } else {
+            1
+        };
         Self {
-            tty_in: BufReader::with_capacity(1024, TtyIn { fd, sigwinch_pipe }),
+            tty_in: BufReader::with_capacity(buffer_size, TtyIn { fd, sigwinch_pipe }),
             timeout_ms: config.keyseq_timeout(),
             parser: Parser::new(),
             key_map,

Or maybe the expect file could be like this:

spawn cargo run --example numeric_input
send "1\n"
expect "1"
spawn cargo run --example numeric_input
send "2\n"
expect "2"

?

from rustyline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.