vonshednob / pter

Manage your todo.txt in a commandline user interface (TUI)
https://vonshednob.cc/pter/
MIT License
102 stars 6 forks source link

Patch to add an external viewer command #42

Closed andrei-a-papou closed 5 months ago

andrei-a-papou commented 6 months ago

I've added the ability to view notes in an external viewer. Rationale: I keep notes in Markdown files and sometimes I just need to view them without editing. I run pter in a minimal Docker container that is ill-suited for running GUI Markdown editors that can also preview things.

Hence this quick patch. The viewer function will look for viewer = under [General], falling back to less if the config setting is unset. Parameters can be passed to the viewer binary, here's what I use for *.md files: viewer = batcat --paging always

96-view-note-1.diff.gz 96-view-note-2.diff.gz 96-view-note-3.diff.gz 96-view-note-4.diff.gz

These patches will apply against 3.15.2 -- albeit with some offsets (since I have other local patches applied before them). Things seem to work OK, please let me know if there are any problems.

vonshednob commented 6 months ago

Good idea; I don’t use another viewer than my editor, but I see how it can be useful.

Thanks a lot for contributing as much as you do, I’m really grateful!

andrei-a-papou commented 6 months ago

No problem, happy to help!

vonshednob commented 6 months ago

I'm not sure yet how to do this, but have a look at this commit: it's possible to use the note parameter in hooks.

Maybe there's a way here to (for example), have pter run in something like tmux and set up the on-select hook to automatically open (reuse?) a note viewer in a split panel right next to pter. Maybe. I don't have the time to check how to do this in detail, but it should be possible.

Anyway, I'll still pull your changes in :grin:

andrei-a-papou commented 6 months ago

Sounds like a good idea. I had some problems running pter in tmux (I think some keys failed to work, but this may have been fixed by now.) I'll check it out!

andrei-a-papou commented 6 months ago

Just in case, here's the same patch set, only against https://codeberg.org/vonshednob/pter/commit/0f1a4bcfd045f0123be2604d75e4714a396740a9:

96-view-note-1.diff.gz 96-view-note-2.diff.gz 96-view-note-3.diff.gz 96-view-note-4.diff.gz 96-view-note-5.diff.gz

andrei-a-papou commented 6 months ago

After more testing, I've switched to viewer = nano --restricted --view --nohelp instead of less. I use nano as the external editor, so this makes sense. And nano is used as a fallback value for editor anyway.

I've also discovered that when a pager like less or batcat --pager always is used, you can press Ctrl-C to exit the viewer abnormally, which crashes pter. Perhaps Ctrl-C can be trapped, I don't know, but I've set up nano as both editor and viewer with a custom nanorc and this works great for me.

In any case, I would suggest defaulting to nano --view as a fallback viewer.

vonshednob commented 5 months ago

less works fine once Ctrl+C is caught. So I used less and more as the fallbacks. Also -- it's in!

andrei-a-papou commented 5 months ago

less works fine now, yes!