diff --git a/main.cpp b/main.cpp index 3536e1f..0abafee 100644 --- a/main.cpp +++ b/main.cpp @@ -120,6 +120,20 @@ static std::vector read_clipboard() { return data; } +static void write_clipboard(const std::string &text) { + const char *cmd; + if (getenv("WAYLAND_DISPLAY")) { + cmd = "wl-copy 2>/dev/null"; + } else { + cmd = "xclip -selection clipboard 2>/dev/null"; + } + FILE *pipe = popen(cmd, "we"); + if (!pipe) + return; + fwrite(text.data(), 1, text.size(), pipe); + pclose(pipe); +} + static std::string capture_screenshot(bool quiet) { const char *tmpdir = getenv("TMPDIR"); if (!tmpdir) @@ -507,6 +521,8 @@ int main(int argc, char **argv) { printf("\n"); } + write_clipboard(ocr_text); + llama_batch_free(batch); llama_sampler_free(smpl); mtmd_free(ctx_vision);