-
Notifications
You must be signed in to change notification settings - Fork 88
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
Make it possible to leave "follow forever" mode without pressing Ctrl+C #49
Comments
This is partially related to #6. |
I made an attempt at this using select() but did not come up with a working solution. I abandoned the effort for now but saved my results in the alt-intr-char branch for future reference. |
Related to #62. |
I tried with |
Well, poll and select perform very similar functionality, and it's not immediately clear to me that it would be any easier to implement using poll vs. select. In the Linux kernel, at least, both poll and select use the same mechanism (they both call f_op->poll on the file). In what way do you think that using poll would be better than select? |
It has been a while, but the issue with
Or maybe I'm missing something and you tried something different with Maybe we can move this discussion on #6. |
Related unix.stackexchange.com question Is there any way to exit “less” follow mode without stopping other processes in pipe? with answers giving workarounds using shell features to supress ctrl+c propagation across processes involved in a pipe. |
I do not see what is difficult there. At least in Bash shell you could put the reading process in background and wait for keypress like this:
You could pipe some appending input for
Though I do not understand why it writes only a screen of text without user interaction; Ctrl + C, F helps. |
Yes, that's strange. @gwsw Any thoughts on the possible reason for this behaviour? |
In the second example you are piping a string of alphanumerics with no newlines into less. In other words, the file is one infinitely long line. Less doesn't handle a case like that well; it expects lines to be separated by newlines. |
As of 5bf862f, you should be able to exit F mode with control-X, in environments where poll() is supported. |
Nice! So Since we use |
The original request in this issue was to provide a way to exit F mode without terminating other processes in a pipe, which the ^X achieves. It sounds like you're asking for something different, or further, which is to avoid the need to enter a special interrupt character at all, but just allow any keypress to interrupt the read, and then get interpreted as a command. Am I understanding correctly? So your idea would just save one keypress in this situation? |
Yes, but my idea would be was to do this only once we can detect that the input pipe is closed. |
Ok, I understand what you are saying and I agree. I will continue discussion in #6. |
Does this help to solve #62? Why not use q as shortcut? |
The technique used to solve #49 might be usable to solve #62, but the current implementation does not solve #62, so I am reopening that issue. I prefer to use ^X rather than q to exit follow mode because of the potential for accidentally quitting less. If you're in follow mode and you press q to exit, and the screen does not refresh immediately because of system load or network lag, you might hit q again, and then find that you've unexpectedly exited less when both q's are processed. |
What happens with the stdout from the pipe once F mode is left? Is it buffered? And can one resume F mode (and then get the output that happened in the meantime)? |
@calestyo It is buffered and you get output that happened in the meantime :) |
@calestyo It's buffered until it's not due to the limited size of pipe's buffer – see How big is the pipe buffer? |
@gwsw Sorry for bothering you, I was just wondering which release this feature (^X) was released in? 🙂 I'm on Arch Linux with |
Yes, ^X should be supported in less-590, but it requires the OS to support poll(). If you built less yourself, you can check the definition of HAVE_POLL in defines.h to see whether less thinks the OS has poll(). If HAVE_POLL is set, another more disturbing possibility is that the OS supports poll() but it doesn't work correctly. This is the case in MacOS. I don't know much about Arch Linux so I don't know what support there is for poll(). |
I tried building from the latest master branch.
Pressing Ctrl+X still has no effect. I tried this in both Alacritty and xfce4-terminal, to rule out any terminal emulator keybindings eating the Ctrl+X. I'm testing with this command:
When I press Ctrl+X, nothing happens. Does this work for you? |
You are correct that this does not work. Less checks for a ctrl-X keypress just before each read() from the input file. While less is stuck in a blocked read, it cannot see any keys from the terminal. So a case like this would work
But if the pipe is producing no data ctrl-X won't work. I think fixing this would require using poll() on the input pipe before each read to confirm that there is data ready to be read. I've done a little work on this but it's not trivial (in particular I haven't found a good way to detect EOF if I'm avoiding calling read() when there is no data available). Meanwhile I am reopening this issue. |
This should be fixed in less-614. |
Should it work on MacOS? |
No, less uses poll() to detect when the ctrl-X key is pressed, but unfortunately poll does not work on /dev/tty on MacOS. In a5bdb60 the "waiting for data" prompt will indicate whether it's supported on a particular system. |
It appears that the MacOS poll() bug has been fixed in newer releases (Big Sur seems to work for me), so as of fe1526f (less-617), ctrl-X will work on MacOS if the first component of |
This seems to work perfectly! 🚀 Awesome job! Now I just need to wait for this version to drop in Arch linux, which is currently on 608 😄 |
When piping the output of a long running process to less, the follow forever (
F
) command is very useful for keeping the freshest content on the screen, but unfortunately there doesn't seem to be a way to leave follow mode without also stopping the process producing output (CtrlC).Would it be possible to add a keyboard shortcut for stopping follow forever mode without affecting other processes in the pipe?
(I suspect this is impossible, or at least extremely difficult, but it doesn't hurt to ask)
The text was updated successfully, but these errors were encountered: