jarun / nnn

n³ The unorthodox terminal file manager
BSD 2-Clause "Simplified" License
19.16k stars 760 forks source link

Unified feature-full preview-* script #627

Closed marioortizmanero closed 4 years ago

marioortizmanero commented 4 years ago

I was setting up nnn the other day (really good job, I love it!) and I found the preview scripts a bit too minimal (I know they've been released recently and they're being worked on). While I really liked how straightforward it was to understand and configure, I think a feature-full plugin that unifies preview-kitty, preview-tui and preview-tabbed could be quite interesting and easier to set-up. One of my issues was that some features were available on the tui script, but not on the kitty one, so I had to copy-paste code between them.

How about following a more ranger-like approach in this one, and having a complete and configurable preview script for everything? Here's theirs, scope.sh. It's quite similar to what one would expect on nnn previews (text previews, images...). It's supposed to be a standalone script; I tried to build a wrapper around it so that it can be used in nnn, too, and I'd say it's possible.

I replied to some post by @jarun a few days back on Reddit and he suggested me to open an issue here. I also mentioned in that message an issue I was having with specifically the preview-kitty script, but I'm not sure if this should go in a different issue, please let me know. Basically, when you use preview-kitty and open a file, the preview window remains open. It'd be great to close it once you open a file, and re-open it once you go back, but I'm not sure how this could be done, and if it happens with other preview scripts. Here's an example:

image

I press return or l

image

I could definitely help with the scripts. Let's just discuss what can be done first.

jarun commented 4 years ago

I think a feature-full plugin that unifies preview-kitty, preview-tui and preview-tabbed could be quite interesting and easier to set-up.

Please feel free to write one and contribute it back an a unified plugin. During development we figured that keeping them separate is a simpler way to maintain.

Basically, when you use preview-kitty and open a file, the preview window remains open.

Now we are seeing a use case where people want this to happen so they can edit a file (say markdown, man page, html) and view the update live in the preview window. That contradicts your use case and we can't have them both. I would suggest you have the option to close the preview window in your unified plugin.

@leovilok is there a possibility of closing the preview window by pressing a key in the preview window?

leovilok commented 4 years ago

@jarun well you can just close the preview window (I think that in both preview-kitty and preview-tui Ctrl+C will work) but it won't get back automatically, you'll have to restart the plugin (which is Alt+\<preview plugin key> in the nnn window).

@marioortizmanero it's hard to close the preview window when a file is opened because the only thing we know about nnn from inside the preview script is the hovered file (and if nnn exited). So the previewer knows nothing about what actions you are doing in nnn.

jarun commented 4 years ago

(I think that in both preview-kitty and preview-tui Ctrl+C will work) but it won't get back automatically, you'll have to restart the plugin (which is Alt+ in the nnn window)

Thanks! I have updated the Live Previews page with the info.

jarun commented 4 years ago

@marioortizmanero for the unified plugin can I add a line item in the ToDo list and assign it to you?

marioortizmanero commented 4 years ago

Now we are seeing a use case where people want this to happen so they can edit a file (say markdown, man page, html) and view the update live in the preview window.

Hmm that's super interesting, I didn't think of this use case. But I'm not sure if that should be nnn's job? For Markdown and Latex I just open a tab in my explorer (with Grip and Vimtex in vim, respectively), for example. And I think closing the preview window is the more popular choice in this case.

@marioortizmanero it's hard to close the preview window when a file is opened because the only thing we know about nnn from inside the preview script is the hovered file (and if nnn exited). So the previewer knows nothing about what actions you are doing in nnn.

Can't the FIFO be used to notify kitty? I'm not too sure about how the FIFO works, but if it was similar to some kind of API it'd be somewhat simple. This might not fit in your KISS philosophy, but what if the FIFO was something more than just the filenames?

hovered: 1234.txt
opened: 1234.txt
closed: 1234.txt

Not sure, just trying to give some ideas. I'm sure this would be useful for other things, too. In my new script closing the window could also be customizable.

Please feel free to write one and contribute it back an a unified plugin. During development we figured that keeping them separate is a simpler way to maintain.

Sure! I don't currently have much time but I'll be experimenting with a complete preview file. You can assign it to me but I can't confirm it'll be ready for the next version.

jarun commented 4 years ago

And I think closing the preview window is the more popular choice in this case.

Not necessarily. After this was discussed in another issue I made the terminal full screen and tried some minor edits in the markdown readme and man page of the project and it was indeed a new way of doing it.

This might not fit in your KISS philosophy

In addition to my above response where I find the open preview useful:

I see you are trying to bring in some intelligence but I would argue that we want to couple less with the previewers. I don't find pressing ^C in the preview window (when you are done with a preview) very inconvenient. Even in multi pane terminals or tmux you have to go to the pane and close it.

You can assign it to me but I can't confirm it'll be ready for the next version.

That's not a problem. I will keep it up for grabs. If you are done before someone else picks it up, just raise the PR.