PaulJuliusMartinez / jless

jless is a command-line JSON viewer designed for reading, exploring, and searching through JSON data.
https://jless.io
MIT License
4.79k stars 92 forks source link

use a channel for stdin and SIGWINCH #128

Closed yshavit closed 1 year ago

yshavit commented 1 year ago

note I have only tested this on macOS. If someone can test it on linux for me, I'd appreciate it!

By using a channel, we can remove the need for calling libc::poll on the stdin pipe. This doesn't work on the Mac: when we redirect tty to stdin, it breaks the original stdin pipe (fd 0), such that libc::poll on it returns instantly, with an revents of POLLNVAL (invalid pipe). Also, macOS doesn't support libc::poll on devices, so we can't poll tty directly.

Instead, we spawn two threads: one just reads stdin forever, and the other uses the socket to listen for SIGWINCH events as before (using libc::poll). These both write to a channel, and the TuiInput simply reads from this channel.

There's no attempt to interrupt or join the two threads: they both just go on as long as the program does. I can add a "stop listening" signal if you like, but that felt like unnecessary complication given the current flow.

This fixes #2.

yshavit commented 1 year ago

Update: I also removed the pipe from the SIGWINCH side of things, so that we don't have any pipes/sockets at all. Each path just grabs its events as simply as possible (for stdin, just read forever; for sigwinch, using the Signals iterator) and sends them to the mpsc channel.

ohshazbot commented 1 year ago

fwiw, this seems to work fine on Ubuntu 22.04

yshavit commented 1 year ago

@PaulJuliusMartinez any thoughts on this one? Even if you don't release a new version of jless, it'd be nice to just get this PR off my queue if it's acceptable to you. (Or to close it if it's not.)

yshavit commented 1 year ago

Closing this PR for lack of development on the project. @PaulJuliusMartinez feel free to reopen and merge if you want.