-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Keyboard arrow keys not working for scrolling from STDIN, rather shows keycode of the key pressed #1006
Comments
Thank you for the detailed report!
I can confirm this.
Oh, that's wrong. This tries to start a pager named "never" 😄. Try Interestingly, piping to npx makemehapi print | less -FR So it really seems like I don't really know what's going on here. I was expecting The bug can not be reproduced if the output is first piped to a file. This works just fine:
|
@sharkdp I just tried the following test cases:- npx makemehapi print | less -Fr # this works just fine. arrow keys work
npx makemehapi print | less -FR # arrow keys work for me here too
But with bat setting after trying to use A weird thing is trying the below command results in a very weird result full of keycodes:- npx makemehapi print | bat --pager 'less -F'
If we add a How
|
One more thing I found out: this works perfectly fine: unbuffer makemehapi print | bat This probably means that something weird is going on with buffering/flushing when Note that Another weird thing is that (the interactive version of) |
That is expected. Those are the ANSI escape sequences for colorization. Even if there is no syntax highlighting, |
@sharkdp The |
I don't know. I would definitely like to understand what's going on here 😄. Even if this seems like something that doesn't occur very frequently.
I don't know. We would first need to understand what's going on. Maybe by trying to build a minimal example program that would show the same behavior. |
That makes sense. Lets leave the issue open till a proper solution is figured out. |
OS: Linux (Arch) | bat: 0.15.4 I have the same issue with the output of several Node.js (v14.9.0) programs, e.g. Doesn't happen with all Node.js programs, though. e.g. these are fine: It's not caused by a specific third-party dependency because, e.g., pidtree doesn't have any. |
@chocolateboy Thank you for the information. I can verify this for Side note (CC @eth-p): |
I came up with the following when looking for a minimal node program. Seems to be something intrinsic to
but if I change the end condition to either 1000 or 100000, i.e. either higher or lower, I can not reproduce! However, taking
So, very strange. Do you see the same thing? Maybe the number used to reproduce depends on how fast your machine is or something weird like that. For the record, I use the following versions, on a MacBook Pro from 2018.
|
I can reproduce this without any It really seems to be something timing dependent, because if I change the sleep from 10ms to 1ms, the bug goes away. Likewise, if I change the sleep from 10ms to 100ms, the bug goes away. It also seems to be It would be very helpful for to know if it is easy for others to reproduce as per below. If others also easily can reproduce using the below method, the next step is perhaps to see if it can be reproduced in some language other than Rust, to know if this is a rust-specific problem. If not, a bug should perhaps be filed against the Node project... Anyway, here is how I can easily reproduce without any main.rs fn main() {
std::thread::sleep(std::time::Duration::from_millis(10));
let child = std::process::Command::new("less")
.stdin(std::process::Stdio::piped())
.spawn()
.unwrap();
let mut child_stdin = child.stdin.unwrap();
// Press Ctrl + C to exit via SIGINT
let mut i = 0;
loop {
i += 1;
use std::io::Write;
child_stdin.write_all(format!("{}\n",i).as_bytes()).unwrap();
}
} Compile (I use rustc main.rs Reproduce: node -e '1' | ./main |
Sorry for somewhat spamming this bug report, but I've started to obsess about getting to the bottom of this bug. Latest news is that this seems to be a regression in Looking at the changelog of They are messing around with file descriptors 0-2, i.e. stdin among other things. And since they ostensibly do it upon exiting node, it would explain the dependence upon specific timing (the exit of node) and thus the need to have sleeps in the repro code. I'll see if I can come up with a convincing bug report for the node project. To be continued... |
I love it.. keep investigating 😄 👍 |
Not for me ( |
Sorry for my slow pace, but I have a full-time job and a family, so spare time is a bit limited ;) After quite a bit of research and debugging involving custom builds with custom debug prints in both Summary This issue should be fixable, or at least greatly mitigated, by making Details Primer on input from terminals Terminals can be in many modes, but the most common are commonly called "raw mode" and "canonical mode". In "raw mode", a Note that the terminal mode is per-terminal. This means that if two processes use the same terminal, the terminal mode is shared, even if different file descriptors in different processes are used. How less uses terminal modes When How node uses terminal modes When How the original problem occurs The problem occurs like this. Note that
How making bat start less quicker will fix the problem Assuming
Explanation of reproducibility examples The reason The reason The reason The reason You will get the same bug with pure The reason that Closing words of this comment Ok, that was a mouthful... I think the next step here is a proof-of-concept patch that makes |
Excellent analysis - thank you very much!
Hm. But we haven't seen similar problems with other programs. I would rather expect for (var i = 0; i <= 20000; i++) { console.log(i); }
Ok, but it has a good reason to change the terminal mode. |
Well, I actually prefer the
it will mess up your terminal because
Although I must admit that one can make a good argument for that the On the surface of it, yes, it seems unnecessary for I took a shot at it but it's a hard nut to crack. Even if you for proof-of-concept temporarily get rid of the slow things that happens before Right now my best bet for this is to make a fast-path to |
Hi, I got the same issue today with the AWS |
Curious to know if there's any new thinking on this issue. I'm running into it with -- : uname -a : bat --version : node --version |
Just for additional information, I experienced the same issue when running This is the buf CLI tool for working with Protocol Buffers, which is written in Go, not Node - so I thought it seemed this bug wasn't restricted to Node tools. The However, I realized I had installed the buf CLI with That's as far as I got, since I solved my own issue, but hopefully this is helpful data point. I wonder if there's any way to detect buffered input piped to |
What version of
bat
are you using?bat 0.15.0
Describe the bug you encountered:
Using keys to scroll through the long STDIN is emitting keycodes, rather than actually scrolling down. Some terminal details:-
Context
I was trying to pass the stdin from the node/npm package makemehapi to bat.
npx makemehapi print | bat
The content was a lengthy output. Thus i tried scrolling with arrow keys like i usually do. But currently the keycodes of the key pressed is displayed rather than actually scrolling down.
cat longFile | bat
works just fine. Arrow keys work there.Content with paging and error - keycodes of arrow keys displayed at bottom
Content with paging and
--show-all
and error - keycodes of arrow keys displayed at bottomThings I have tried
bat --pager=never
still no usebat --no-config
still no use...
Describe what you expected to happen?
...
To be able to scroll through the long content using arrow keys or even Page Down/UP keys without having to press ENTER for each line.
How did you install
bat
?yay -S bat
Info.sh
system
$ uname -srm
Linux 5.6.13-arch1-1 x86_64
bat
$ bat --version
bat 0.15.0
$ env
BAT_PAGER=less -RF
bat_config
$ cat /home/ikigai/.config/bat/config
bat_wrapper
No wrapper script for 'bat'.
bat_wrapper_function
No wrapper function for 'bat'.
No wrapper function for 'cat'.
tool
$ less --version
less 551 (PCRE regular expressions)
Full STDOUT of
npx makemehapi print
The text was updated successfully, but these errors were encountered: