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

External printer sometimes omits messages until more input is given #629

Closed
JanBeh opened this issue May 1, 2022 · 8 comments
Closed

External printer sometimes omits messages until more input is given #629

JanBeh opened this issue May 1, 2022 · 8 comments

Comments

@JanBeh
Copy link

JanBeh commented May 1, 2022

I'm using FreeBSD and xterm and tried the new external printer feature.

When I type in text, the program and/or terminal sometimes gets into a state where no more messages are being emitted. I used this example code, with slightly adjusted timings:

-            let wait_ms = rng.gen_range(1000..10000);
+            let wait_ms = rng.gen_range(500..1000);

This is how my terminal looks like after I type in some text when I'm unlucky:

% cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/readnwrite`
External message #0
External message #1
External message #2
External message #3
> ghdflghdfjkhd

At this point, no more output will be created, even if I wait for a long time. I then typed a few x characters, and this happened:

% cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/readnwrite`
External message #0
External message #1
External message #2
External message #3
External message #32
External message #33
External message #34
External message #35
External message #36
External message #37
External message #38
> ghdflghdfjkhdfxxxxxx
Error: Interrupted

Note that also an f appeared after ghdflghdfjkhd and before the xxxxxx. That f must have been stuck somewhere because I didn't enter it after the state appeared to be blocked.

Messages #4 through #31 got lost in this example.

My setup:

% echo $TERM
xterm
% xterm -v
XTerm(372)
@gwenn
Copy link
Collaborator

gwenn commented May 1, 2022

Sorry but I cannot reproduce on linux/macosx:

$ uname -a
Linux archlinux 5.17.5-arch1-1 #1 SMP PREEMPT Wed, 27 Apr 2022 20:56:11 +0000 x86_64 GNU/Linux
% uname -a
Darwin Gwenaels-MacBook-Air.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64 x86_64
% echo $TERM
xterm-256color

I will try to investigate on a FreeBSD VM...
Would you mind checking if https://github.com/AmokHuginnsson/replxx/blob/master/examples/cxx-api.cxx#L386 has the same issue or not ?
Or checking if there is something wrong while activating debug logs:

 fn main() -> Result<()> {
+    env_logger::init();
     let mut rl = Editor::<()>::new();
     let mut printer = rl.create_external_printer()?;
$ RUST_LOG=rustyline=debug cargo run --example external_print 2> debug.log

Thanks.

@JanBeh
Copy link
Author

JanBeh commented May 1, 2022

I'm happy to help. I'm not much familiar with C++, so I didn't get the example compiled yet.

But I found out something already: I cannot reproduce it if I run the example from the rustyline crate. But when I create my own crate (using rustylines master branch), I get the erroneous behavior.

This is how my Cargo.toml looks like:

[package]
name = "readnwrite"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

rustyline = { git = "https://github.com/kkawakam/rustyline/", rev="280e71191fef234c698fe1d94dedc270a6f37c33" }
#rustyline = "9.1.2"
rand = "0.8.5"
env_logger = "0.9.0"

Can you reproduce the behavior with a separate crate that uses these dependencies?

This is the debug output using env_logger::init() in the erroneous case:

[2022-05-01T18:44:52Z DEBUG rustyline] VEOF: KeyEvent(Char('D'), CTRL)
[2022-05-01T18:44:52Z DEBUG rustyline] VINTR: KeyEvent(Char('C'), CTRL)
[2022-05-01T18:44:52Z DEBUG rustyline] VQUIT: KeyEvent(Char('\\'), CTRL)
[2022-05-01T18:44:52Z DEBUG rustyline] VSUSP: KeyEvent(Char('Z'), CTRL)
[2022-05-01T18:44:52Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 0, row: 0 }, default_prompt: false, cursor: Position { col: 0, row: 0 }, end: Position { col: 0, row: 0 } }
[2022-05-01T18:44:52Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 2, row: 0 }, end: Position { col: 2, row: 0 } }
[2022-05-01T18:44:53Z DEBUG rustyline] initial cursor location: Some(20)
[2022-05-01T18:44:53Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 2, row: 0 }, end: Position { col: 2, row: 0 } }
[2022-05-01T18:44:53Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 2, row: 0 }, end: Position { col: 2, row: 0 } }
[2022-05-01T18:44:54Z DEBUG rustyline] initial cursor location: Some(20)
[2022-05-01T18:44:54Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 2, row: 0 }, end: Position { col: 2, row: 0 } }
[2022-05-01T18:44:54Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 2, row: 0 }, end: Position { col: 2, row: 0 } }
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'h' => key: KeyEvent(Char('h'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'h')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(0, 'h')
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'g' => key: KeyEvent(Char('g'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'g')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(1, 'g')
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'i' => key: KeyEvent(Char('i'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'i')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(2, 'i')
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'k' => key: KeyEvent(Char('k'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'k')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(3, 'k')
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'h' => key: KeyEvent(Char('h'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'h')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(4, 'h')
[2022-05-01T18:44:54Z DEBUG rustyline] c: 'f' => key: KeyEvent(Char('f'), NONE)
[2022-05-01T18:44:54Z DEBUG rustyline] Emacs command: SelfInsert(1, 'f')
[2022-05-01T18:44:54Z DEBUG rustyline] Changeset::insert(5, 'f')
[2022-05-01T18:44:54Z DEBUG rustyline] initial cursor location: Some(20)
[2022-05-01T18:44:54Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 8, row: 0 }, end: Position { col: 8, row: 0 } }
[2022-05-01T18:44:54Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 8, row: 0 }, end: Position { col: 8, row: 0 } }
[2022-05-01T18:44:55Z DEBUG rustyline] initial cursor location: Some(20)
[2022-05-01T18:44:55Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 8, row: 0 }, end: Position { col: 8, row: 0 } }
[2022-05-01T18:44:55Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 8, row: 0 }, end: Position { col: 8, row: 0 } }
[2022-05-01T18:44:55Z DEBUG rustyline] c: 'd' => key: KeyEvent(Char('d'), NONE)
[2022-05-01T18:44:55Z DEBUG rustyline] Emacs command: SelfInsert(1, 'd')
[2022-05-01T18:44:55Z DEBUG rustyline] Changeset::insert(6, 'd')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'g' => key: KeyEvent(Char('g'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'g')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(7, 'g')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'h' => key: KeyEvent(Char('h'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'h')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(8, 'h')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'i' => key: KeyEvent(Char('i'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'i')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(9, 'i')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'o' => key: KeyEvent(Char('o'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'o')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(10, 'o')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 's' => key: KeyEvent(Char('s'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 's')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(11, 's')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'e' => key: KeyEvent(Char('e'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'e')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(12, 'e')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'h' => key: KeyEvent(Char('h'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'h')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(13, 'h')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'r' => key: KeyEvent(Char('r'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'r')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(14, 'r')
[2022-05-01T18:44:56Z DEBUG rustyline] c: 'i' => key: KeyEvent(Char('i'), NONE)
[2022-05-01T18:44:56Z DEBUG rustyline] Emacs command: SelfInsert(1, 'i')
[2022-05-01T18:44:56Z DEBUG rustyline] Changeset::insert(15, 'i')
[2022-05-01T18:44:56Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:44:56Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, 
default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:56Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:57Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:44:57Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:57Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:58Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:44:58Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:58Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:58Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:44:58Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:58Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:59Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:44:59Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:44:59Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:45:00Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:45:00Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:45:00Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:45:01Z DEBUG rustyline] cannot request cursor location
[2022-05-01T18:45:01Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:45:01Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 18, row: 0 }, end: Position { col: 18, row: 0 } }
[2022-05-01T18:45:01Z DEBUG rustyline] c: 'l' => key: KeyEvent(Char('l'), NONE)
[2022-05-01T18:45:01Z DEBUG rustyline] Emacs command: SelfInsert(1, 'l')
[2022-05-01T18:45:01Z DEBUG rustyline] Changeset::insert(16, 'l')
[2022-05-01T18:45:01Z DEBUG rustyline] c: 'x' => key: KeyEvent(Char('x'), NONE)
[2022-05-01T18:45:01Z DEBUG rustyline] Emacs command: SelfInsert(1, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] Changeset::insert(17, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] c: 'x' => key: KeyEvent(Char('x'), NONE)
[2022-05-01T18:45:01Z DEBUG rustyline] Emacs command: SelfInsert(1, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] Changeset::insert(18, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] c: 'x' => key: KeyEvent(Char('x'), NONE)
[2022-05-01T18:45:01Z DEBUG rustyline] Emacs command: SelfInsert(1, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] Changeset::insert(19, 'x')
[2022-05-01T18:45:01Z DEBUG rustyline] initial cursor location: Some(21)
[2022-05-01T18:45:01Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 22, row: 0 }, end: Position { col: 22, row: 0 } }
[2022-05-01T18:45:01Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 22, row: 0 }, end: Position { col: 22, row: 0 } }
[2022-05-01T18:45:02Z DEBUG rustyline] initial cursor location: Some(21)
[2022-05-01T18:45:02Z DEBUG rustyline] old layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 22, row: 0 }, end: Position { col: 22, row: 0 } }
[2022-05-01T18:45:02Z DEBUG rustyline] new layout: Layout { prompt_size: Position { col: 2, row: 0 }, default_prompt: true, cursor: Position { col: 22, row: 0 }, end: Position { col: 22, row: 0 } }
[2022-05-01T18:45:03Z DEBUG rustyline] c: '\u{3}' => key: KeyEvent(Char('C'), CTRL)
[2022-05-01T18:45:03Z DEBUG rustyline] terminal key binding: KeyEvent(Char('C'), CTRL) => Interrupt
Error: Interrupted

And text output was as follows:

$ RUST_LOG=rustyline=debug cargo run --example external_print 2> debug.log
External message #1
External message #2
External message #3
External message #4
External message #12
External message #13
> hgikhfdghiosehrilxxx

@JanBeh
Copy link
Author

JanBeh commented May 1, 2022

Would you mind checking if https://github.com/AmokHuginnsson/replxx/blob/master/examples/cxx-api.cxx#L386 has the same issue or not ?

When I compile it with ./build-all.sh (installation fails due to privileges, but build succeeds), and execute it with build/release/replxx-example-cxx-api m, it works fine.

Note that when I run the example from rustyline it works fine too (as explained in my previous post). The error only happens if I use rustyline in my own crate (which doesn't contain anything except the dependencies and the example file from rustyline).

@gwenn
Copy link
Collaborator

gwenn commented May 2, 2022

Thanks for your investigations.
Could you please try/check with this PR: #627 ?

@JanBeh
Copy link
Author

JanBeh commented May 2, 2022

My deepest apologies! I wrongly used the latest commit of the example file (280e71191f) and not the latest commit of the repository (3852f63570). Was totally my fault (because I'm not as familiar with Git yet and misinterpreted the heading on github when viewing the example file).

With the current version in master all works fine! Sorry again.

@gwenn
Copy link
Collaborator

gwenn commented May 3, 2022

No worry.
And thanks for being a beta tester for this new feature.

@JanBeh
Copy link
Author

JanBeh commented May 5, 2022

Should I close this issue then? (Or you can do it too.)

@gwenn
Copy link
Collaborator

gwenn commented May 5, 2022

Please, do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants