Expand description

Clipboard module

The clipboard feature in Gistit is nothing more than a quality of life bonus to automatically store the Gistit hash into your system clipboard. Since we’re interested in persisting the Gistit hash after the program exists we have to rely on not so reliable methods to achieve this behaviour.

Here we do our best efforts look for the most common clipboard binaries, spawn a child process, and pipe the contents into it’s ‘stdin’. If no binary was found we’ll fallback to OSC52 escape sequence. OSC52

credits: this implementation is heavily inspired on copypasta

note we’re not interested in ‘paste’ functionallity

Linux/BSD

On Linux/BSD we’ll match the display server and attempt to find related clipboard binaries.

WSL

Will use clip.exe to pipe content into.

X11

Will look for xclip, xsel and use it in this order of preference.

Wayland

Will look for wl-copy binary.

Tty (SSH session)

Under this condition we’ll do a couple of extra checks to ensure X11 Passthrough is working, otherwise clipboard usage is unlikely to succeed (?).

  1. checks for xauth binary, utility to manage X11 session cookies.
  2. reads DISPLAY env variable to ensure it’s set with ‘localhost:’ something something.

If the above are ok we check for X11 clipboard binaries to use.

Mac OS

We check for pbcopy binary but it’s absence is not a showstopper since we can still try OSC52 escape sequence.

Windows

Doesn’t make sense to check for clip.exe because it’s default installation. Anyhow, we’re not using it under this platform. This can change in the future

Structs

The clipboard that attempts the external binary approach

The clipboard structure, holds the content string

The clipboard that attempts OSC52 escape sequence approach

The clipboard with the display server figured out

Traits

The trait that a ready-to-use clipboard implements