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

Cannot use / to search when piped. #7

Closed
dkowis opened this issue Feb 9, 2022 · 6 comments · Fixed by #32
Closed

Cannot use / to search when piped. #7

dkowis opened this issue Feb 9, 2022 · 6 comments · Fixed by #32
Labels
Bug Something isn't working

Comments

@dkowis
Copy link

dkowis commented Feb 9, 2022

This tool is glorious!

But, I found a problem. If you pipe info to it, say from an aws cli: aws iam list-instance-profiles | jless for example, I cannot search.

Hitting / immediately exits, which was surprising.

@PaulJuliusMartinez PaulJuliusMartinez added the Bug Something isn't working label Feb 9, 2022
@PaulJuliusMartinez
Copy link
Owner

Thank you!

I'm able to reproduce the issue. Looks like it might be an issue with the readline library I'm using, so it might take some time to figure out.

@alimoezzi
Copy link

I also faced this bug when piping the output

@n1000
Copy link

n1000 commented Feb 12, 2022

I ran into this also. From strace it looks like the readline implementation is attempting to read the "/" from fd=0, which is connected to the file being piped as input, not the TTY, and hitting the EOF (since the file has already been fully read):

poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}], 2, -1) = 1 ([{fd=3, revents=POLLIN}])
// the read below on fd 3 looks like a read on sigwinch_pipe by TuiInput
read(3, "/", 1024)                      = 1
write(1, "\33[?25h\33[65;1H\33[0m", 17) = 17
// oops? I think this is a read by rustyline readline_with() (on stdin/the file instead of a terminal connected fd):
read(0, "", 8192)                       = 0
write(1, "\33[?25l\33[65;1H\33[0m\33[2K", 21) = 21
write(2, "thread '", 8thread ')                 = 8
write(2, "main", 4main)                     = 4
write(2, "' panicked at '", 15' panicked at ')         = 15
write(2, "called `Result::unwrap()` on an `Err` value: Eof", 48called `Result::unwrap()` on an `Err` value: Eof) = 48
write(2, "', ", 3', )                      = 3
write(2, "/home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/app.rs", 83/home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/jless-0.7.1/src/app.rs) = 83

I think the rustyline function below might need to support operating on a specific file descriptor (instead of using io::stdin(), which in this case is no longer connected to the terminal):

    fn readline_with(&mut self, prompt: &str, initial: Option<(&str, &str)>) -> Result<String> {
        if self.term.is_unsupported() {
            debug!(target: "rustyline", "unsupported terminal");
            // Write prompt and flush it to stdout
            let mut stdout = io::stdout();
            stdout.write_all(prompt.as_bytes())?;
            stdout.flush()?;

            readline_direct(io::stdin().lock(), io::stderr(), &self.helper)
        } else if self.term.is_stdin_tty() {
            readline_raw(prompt, initial, self)
        } else {
            debug!(target: "rustyline", "stdin is not a tty");
            // Not a tty: read from file / pipe.
            readline_direct(io::stdin().lock(), io::stderr(), &self.helper)
        }
    }

@heyajulia

This comment was marked as outdated.

@jli
Copy link

jli commented Feb 12, 2022

Here's a workaround that doesn't create an intermediate file:

# crashes if you search
curl https://httpbin.org/get | jless

# search works!
jless <(curl https://httpbin.org/get)

@PaulJuliusMartinez
Copy link
Owner

This issue has been fixed and is available in the v0.7.2 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
6 participants