dsanson / termpdf.py

A graphical pdf and epub reader that works inside the kitty terminal
MIT License
496 stars 30 forks source link

quick feedback #5

Closed teto closed 3 years ago

teto commented 4 years ago

Thanks for building something I have been dreaming of for some time ! For various reasons, I've been ditching the excellent mendeley (but closed source with little regards for its users' privacy) in favor of the terminal literature manager https://github.com/papis/papis. In my quest for a terminal pdf reader allowing to take notes, I was desperate and was Imaging a neovim plugin that would use pdf2txt and floating windows to register notes in a side file. Your project looks in many ways better. Here are a few questions:

I wonder if we could have a neovim terminal where we display the image, and have notes as floating windows <3 I understand this is an early version but it's already quite impressive, keep up the good work !

dsanson commented 4 years ago

Thanks! This is all still very much alpha, so features are often a bit half-baked, I'm afraid. I use it with zotero + better bibtex, not papis. At some point, I hope to add direct support for zotero integration, for things like fetching metadata. Adding papis integration would be neat too, but since I don't use papis, isn't something I'm likely to do any time soon.

  1. The script needs some way to know which nvim instance it is supposed to interact with. So, you either need to tell termpdf the listen address of a nvim instance (by passing the --nvim-listen-adress option), or set the address of an nvim instance to `/tmp/termpdf_nvim_bridge'. If you don't do either of those things, termpdf will launch a new nvim instance. Is there a better way to do this?

  2. (a) Right now, you can adjust the visual selection by using h and shift-h to adjust the left side, and l and shift-l to adjust the right side. It should be easy to also allow arrow keys for this. It would be more complicated (but not too complicated) to allow for non-rectangular selections. Anyway, it would be better to have visual selection based on the characters on the page, right?

  3. (b) Do you have a suggestion for how to include additional position information? Would raw pixel coordinates be useful? I should look at how the org-mode tools do this in emacs, and how that gets translated into markdown by pandoc. Ideally, we would have a corresponding plugin in nvim that reads this data and allows one to quickly jump back to the selection in termpdf. Right now, I have a half-assed function in my vimrc that reads the citation key and the page number and uses that info to open the pdf file.

  4. I haven't implemented zooming in and out for PDFs. I'm not sure how flexible an implementation should be, or how to implement navigation for zoomed pages. Probably my personal use top priority is a mode for viewing two-up PDFs one page at a time. For now, "zooming" only works for "reflowable" formats supported by pymupdf, like ePub.

I don't think I can reliably use ncurses interfaces over the top of the displayed images, as ncurses tends to clobber the image when it refreshes the text. In the same way, I don't think there is much of a chance that one can use kitty to display images within an nvim window, or use nvim popups to display annotations.

teto commented 4 years ago
  1. Even if I pass a valid socket, it seems like it opens a new instance but it doesn't really matter for me (and I can fix it when it will).
  2. Wow that's amazing ! only issue I noticed with a coworker is that when yanking the selection, it removes spaces: for instance Interactiveapplicationsdonotrequiremorebandwidthto gofaster.Instead,theyrequirelesslatency.
  3. I am not sure, the pdf spec is such an abomination I trust you and pymupdf on this: whatever is possible I guess :)
  4. I don't know what's available in pymupdf but that would be cool to have modes like in zathura (adjust to terminal width is the one I am thinking off) to get rid of the empty left and right margins 2019-10-03-152348_1532x999_scrot

I don't think I can reliably use ncurses interfaces over the top of the displayed images, as ncurses tends to clobber the image when it refreshes the text. In the same way, I don't think there is much of a chance that one can use kitty to display images within an nvim window, or use nvim popups to display annotations.

As one can launch a terminal in neovim (:term) I think that's within the realm of possible. I've just tried but it failed with Terminal does not support reporting screen sizes via the TIOCGWINSZ ioctl, even when overriding TERM to xterm-kitty. Which means one would need to implement TIOCGWINSZ in neovim's term :(

dsanson commented 4 years ago

As one can launch a terminal in neovim (:term) I think that's within the realm of possible. I've just tried but it failed with Terminal does not support reporting screen sizes via the TIOCGWINSZ ioctl, even when overriding TERM to xterm-kitty. Which means one would need to implement TIOCGWINSZ in neovim's term :(

Right. I don't expect nvim's term to support TIOCGWINSZ.

dsanson commented 4 years ago

Even if I pass a valid socket, it seems like it opens a new instance but it doesn't really matter for me (and I can fix it when it will).

That sounds like a bug!

dsanson commented 4 years ago

only issue I noticed with a coworker is that when yanking the selection, it removes spaces: for instance Interactiveapplicationsdonotrequiremorebandwidthto gofaster.Instead,theyrequirelesslatency.

Have you tried it on multiple PDFs? For the most part, my results have been decent. The main thing I've noticed is that words will sometimes be moved a line above or below where they are supposed to be. But I am not doing anything to carefully glue the text together, so your results are going to depend a lot on how the text is encoded in the PDF itself. There are things that could be done to try to more carefully attend to how the text is laid out, and to make more intelligent guesses about how it is supposed to fit together.

dsanson commented 4 years ago

I don't know what's available in pymupdf but that would be cool to have modes like in zathura (adjust to terminal width is the one I am thinking off) to get rid of the empty left and right margins

Yes. This is something I plan to implement at some point!

teto commented 4 years ago

One point I forgot to mention, if I send termpdf to background (ctrl+z) and resume it with fg, then my screen gets black. Forcing a redraw solves it. Maybe it's a bug in kitty (altscreen?) but you may want to catch the resume signal and force a redraw.

teto commented 3 years ago

thanks for the answers.