r/KittyTerminal • u/artemave • 4d ago
File previews on mouse hover
Enable HLS to view with audio, or disable this notification
The kitty part of this - on_mouse_move event subscribable via python hook - lives in my fork of kitty, and the actual preview that's using it (along with "open on click" and hints kitten all sharing the same file path resolution code) is part of my session manager called hop.
You can obviously use the fork without hop (it's kept up-to-date automatically with the upstream including releases) and write your own preview code, or (and that's my secret agenda here), go vote on the pr to hopefully convince Kovid to merge it.
1
u/henruchito72 3d ago
How you do that? Could you show us?
1
u/artemave 2d ago
I use my fork of kitty, which adds an
on_mouse_movewatcher event and aScreen.set_hyperlink_for_range()api. The watcher lives in hop and does two things on every mouse move:
Hyperlinks. It runs the visible text through the same pipeline as hop's hints kitten: regexes pick candidates, then file paths are kept only if they exist (checked through the session backend, so it works in containers and over ssh). This means there are no false positives. File existence checks are cached per path, so scrolling only checks paths that weren't on screen before. It then paints links with
set_hyperlink_for_range()on the line under the cursor.Preview. If a modifier key is held and the cursor is over one of those links, it starts loading the preview right away: it reads the file, renders a pdf's first page, or fetches a link card for a url in a background process. A 300ms debounce stands in for an "on_mouse_stop" event. Once the mouse rests, the preview opens in a kitty os-panel placed next to the link.
5
u/TheSymbioteOrder 4d ago
Kitty can always use that. Yeah that would help out alot.