{"id":13805498,"url":"https://github.com/ChurchTao/clipboard-rs","last_synced_at":"2025-05-13T19:31:13.343Z","repository":{"id":219448586,"uuid":"748121356","full_name":"ChurchTao/clipboard-rs","owner":"ChurchTao","description":"Cross-platform clipboard API (text | image | rich text | html | files | monitoring changes) | 跨平台剪贴板 API(文本|图片|富文本|html|文件|监听变化) Windows,MacOS,Linux","archived":false,"fork":false,"pushed_at":"2024-10-23T02:06:11.000Z","size":466,"stargazers_count":59,"open_issues_count":5,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-24T15:09:38.582Z","etag":null,"topics":["clipboard","cross-platform","electron","rust","tauri"],"latest_commit_sha":null,"homepage":"https://docs.rs/clipboard-rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChurchTao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-25T10:16:17.000Z","updated_at":"2024-10-23T10:49:20.000Z","dependencies_parsed_at":"2024-11-13T07:03:45.842Z","dependency_job_id":"395fa6c8-525a-44f7-be57-438e9b362b77","html_url":"https://github.com/ChurchTao/clipboard-rs","commit_stats":{"total_commits":98,"total_committers":6,"mean_commits":"16.333333333333332","dds":0.3163265306122449,"last_synced_commit":"f7513e25c213c40c9b68800b4039e8f5f152ed3f"},"previous_names":["churchtao/clipboard-rs"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChurchTao%2Fclipboard-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChurchTao%2Fclipboard-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChurchTao%2Fclipboard-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChurchTao%2Fclipboard-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChurchTao","download_url":"https://codeload.github.com/ChurchTao/clipboard-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225254340,"owners_count":17445166,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clipboard","cross-platform","electron","rust","tauri"],"created_at":"2024-08-04T01:01:01.750Z","updated_at":"2025-05-13T19:31:13.295Z","avatar_url":"https://github.com/ChurchTao.png","language":"Rust","funding_links":[],"categories":["Applications"],"sub_categories":["System tools"],"readme":"# clipboard-rs\n\n[![Latest version](https://img.shields.io/crates/v/clipboard-rs?color=mediumvioletred)](https://crates.io/crates/clipboard-rs)\n[![Documentation](https://docs.rs/clipboard-rs/badge.svg)](https://docs.rs/clipboard-rs)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ChurchTao/clipboard-rs/test.yml)\n![MSRV](https://img.shields.io/badge/rustc-1.67+-blue.svg)\n![GitHub License](https://img.shields.io/github/license/ChurchTao/clipboard-rs)\n\nclipboard-rs is a cross-platform library written in Rust for getting and setting the system-level clipboard content. It supports Linux, Windows, and MacOS.\n\n[简体中文](README_ZH.md)\n\n## Function Support\n\n- Plain text\n- Html\n- Rich text\n- Image (In `PNG` format)\n- File (In `file-uri-list` format)\n- Any type (by specifying the type identifier) can be obtained through the `available_formats` method\n\n## Development Plan\n\n- [x] MacOS Support\n- [x] Linux Support (x11)\n- [x] Windows Support\n\n## Usage\n\nAdd the following content to your `Cargo.toml`:\n\n```toml\n[dependencies]\nclipboard-rs = \"0.2.4\"\n```\n\n## [CHANGELOG](CHANGELOG.md)\n\n## Examples\n\n### All Usage Examples\n\n[Examples](examples)\n\n### Simple Read and Write\n\n```rust\nuse clipboard_rs::{Clipboard, ClipboardContext, ContentFormat};\n\nfn main() {\n\tlet ctx = ClipboardContext::new().unwrap();\n\tlet types = ctx.available_formats().unwrap();\n\tprintln!(\"{:?}\", types);\n\n\tlet has_rtf = ctx.has(ContentFormat::Rtf);\n\tprintln!(\"has_rtf={}\", has_rtf);\n\n\tlet rtf = ctx.get_rich_text().unwrap_or(\"\".to_string());\n\n\tprintln!(\"rtf={}\", rtf);\n\n\tlet has_html = ctx.has(ContentFormat::Html);\n\tprintln!(\"has_html={}\", has_html);\n\n\tlet html = ctx.get_html().unwrap_or(\"\".to_string());\n\n\tprintln!(\"html={}\", html);\n\n\tlet content = ctx.get_text().unwrap_or(\"\".to_string());\n\n\tprintln!(\"txt={}\", content);\n}\n\n```\n\n### Reading Images\n\n```rust\nuse clipboard_rs::{common::RustImage, Clipboard, ClipboardContext};\n\nconst TMP_PATH: \u0026str = \"/tmp/\";\n\nfn main() {\n\tlet ctx = ClipboardContext::new().unwrap();\n\tlet types = ctx.available_formats().unwrap();\n\tprintln!(\"{:?}\", types);\n\n\tlet img = ctx.get_image();\n\n\tmatch img {\n\t\tOk(img) =\u003e {\n\t\t\timg.save_to_path(format!(\"{}test.png\", TMP_PATH).as_str())\n\t\t\t\t.unwrap();\n\n\t\t\tlet resize_img = img.thumbnail(300, 300).unwrap();\n\n\t\t\tresize_img\n\t\t\t\t.save_to_path(format!(\"{}test_thumbnail.png\", TMP_PATH).as_str())\n\t\t\t\t.unwrap();\n\t\t}\n\t\tErr(err) =\u003e {\n\t\t\tprintln!(\"err={}\", err);\n\t\t}\n\t}\n}\n\n```\n\n### Reading Any Format\n\n```rust\nuse clipboard_rs::{Clipboard, ClipboardContext};\n\nfn main() {\n    let ctx = ClipboardContext::new().unwrap();\n    let types = ctx.available_formats().unwrap();\n    println!(\"{:?}\", types);\n\n    let buffer = ctx.get_buffer(\"public.html\").unwrap();\n\n    let string = String::from_utf8(buffer).unwrap();\n\n    println!(\"{}\", string);\n}\n\n```\n\n### Listening to Clipboard Changes\n\n```rust\nuse clipboard_rs::{\n\tClipboard, ClipboardContext, ClipboardHandler, ClipboardWatcher, ClipboardWatcherContext,\n};\nuse std::{thread, time::Duration};\n\nstruct Manager {\n\tctx: ClipboardContext,\n}\n\nimpl Manager {\n\tpub fn new() -\u003e Self {\n\t\tlet ctx = ClipboardContext::new().unwrap();\n\t\tManager { ctx }\n\t}\n}\n\nimpl ClipboardHandler for Manager {\n\tfn on_clipboard_change(\u0026mut self) {\n\t\tprintln!(\n\t\t\t\"on_clipboard_change, txt = {}\",\n\t\t\tself.ctx.get_text().unwrap()\n\t\t);\n\t}\n}\n\nfn main() {\n\tlet manager = Manager::new();\n\n\tlet mut watcher = ClipboardWatcherContext::new().unwrap();\n\n\tlet watcher_shutdown = watcher.add_handler(manager).get_shutdown_channel();\n\n\tthread::spawn(move || {\n\t\tthread::sleep(Duration::from_secs(5));\n\t\tprintln!(\"stop watch!\");\n\t\twatcher_shutdown.stop();\n\t});\n\n\tprintln!(\"start watch!\");\n\twatcher.start_watch();\n}\n\n\n```\n\n## X11 - Clipboard Read Timeout\n\nBy default, in X11 clipboard-rs implements a read timeout of 500 ms. You can override or disable this timeout by creating **ClipboardContext** using `new_with_options`:\n\n```rust\n#[cfg(unix)]\nfn setup_clipboard() -\u003e ClipboardContext {\n\tClipboardContext::new_with_options(ClipboardContextX11Options { read_timeout: None }).unwrap()\n}\n\n#[cfg(not(unix))]\nfn setup_clipboard(ctx: \u0026mut ClipboardContext) -\u003e ClipboardContext{\n\tClipboardContext::new().unwrap()\n}\n```\n\n## Contributing\n\nYou are welcome to submit PRs and issues and contribute your code or ideas to the project. Due to my limited level, the library may also have bugs. You are welcome to point them out and I will modify them as soon as possible.\n\n## Thanks\n\n- API design is inspired by [electron](https://www.electronjs.org/zh/docs/latest/api/clipboard)\n- Linux part of the project code is referenced from [x11-clipboard](https://github.com/quininer/x11-clipboard/tree/master)\n\n## Contract\n\nif you have any questions, you can contact me by email: `swkzymlyy@gmail.com`\n\nChinese users can also contact me by wechatNo: `uniq_idx_church_lynn`\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChurchTao%2Fclipboard-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FChurchTao%2Fclipboard-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FChurchTao%2Fclipboard-rs/lists"}