Closed mmastrac closed 6 months ago
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)?;
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
I will try to investigate further... TCSADRAIN
here ?
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 ?
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"
?
I think I am running into this issue when I pipe the output of a command with multiple lines into my app that uses rustyline,
here is a simulation of my example, I can create a code example if needed.
echo "test\ninput" | cargo run rustylineapp
Should produce:
Result: test
input
but it produces
Result: test
Result: input
@cosmikwolf For me, this is the expected behaviour when stdin
is not a tty (here a pipe). expect
creates a pty.
liner % echo "test\ninput" | target/debug/examples/comments history
History file: history
[prompt]
% test
[prompt]
% nput
[prompt]
% exiting...
linenoise % echo "test\ninput" | ./linenoise_example
echo: 'test'
echo: 'input'
replxx % echo "test\ninput" | ./build/replxx-example-c-api
starting...
thanks for the input: test
thanks for the input: input
Exiting Replxx
isocline % echo "test\ninput" | ./example
...
-----
est
-----
-----
input
-----
done
To support type ahead, this module will store all the key strokes that were read too early, so that they can be feed into to the next
prompt()
call
@mmastrac could you please try #761 ?
Version 14.0.0 released
When sending input via
expect
,rustyline
doesn't appear to process anything but the first line.example.expect
Run
expect example.expect
Expected:
Output should be
Num 1
followed byNum 2
.Actual:
Output is just
Num 1
Workaround:
It does work without using
expect
, however: