Skip to content
pi-c Artifact [a3b36d8309]
Login

Artifact [a3b36d8309]

Artifact a3b36d830995ff5f58b9c2e795e131ff76ad612c947941dae3233a9bcd65fccc:


/* The system clipboard as Ctrl+V reads it and a copy writes it (clipboard.c).
 * Host-only: it runs the platform's own commands (osascript, pbpaste and
 * pbcopy on macOS; wl-paste, wl-copy, xclip and xsel on Linux) and nothing is
 * written to disk. */
#ifndef PIC_TUI_CLIPBOARD_H
#define PIC_TUI_CLIPBOARD_H

#include <stddef.h>

enum {
    TUI_CLIP_NONE,  /* nothing usable, or no clipboard here */
    TUI_CLIP_FILES, /* copied files (Finder): absolute paths, one per line */
    TUI_CLIP_IMAGE, /* a PNG, JPEG, GIF or WebP image */
    TUI_CLIP_TEXT,
};

typedef struct {
    char *text;           /* TUI_CLIP_FILES (paths) or TUI_CLIP_TEXT: malloc'd */
    unsigned char *image; /* TUI_CLIP_IMAGE: malloc'd, image_len bytes */
    size_t image_len;
} tui_clip;

/* Pi's handleClipboardPaste order: copied files, else an image, else text.
 * Returns the kind found, with its field set (free it); the others are NULL.
 * Tests point it at files instead, which also keeps them off the real
 * clipboard: PIC_CLIPBOARD_FILES_FILE (its lines are the paths),
 * PIC_CLIPBOARD_IMAGE_FILE (the image bytes) and PIC_CLIPBOARD_TEXT_FILE;
 * with PIC_NO_NATIVE_CLIPBOARD set and no such file, nothing is found. */
int tui_clipboard_read(tui_clip *c);
void tui_clip_free(tui_clip *c);
/* Puts T[0..n) on the system clipboard with the platform's own command
 * (pbcopy on macOS; wl-copy, else xclip or xsel, on Linux): 0, or -1 when
 * there is none (or PIC_NO_NATIVE_CLIPBOARD is set) or it failed. Dev builds
 * run PIC_TEST_CLIPBOARD_CMD instead, the tests' stand-in. */
int tui_clipboard_write(const char *t, size_t n);

#endif