tawasuyu/llimphi
Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.
⎇ 92dd0e5bfb2ca4456006da99437f4100e156d856
widgets/text-editor-core/src/clipboard.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
feat: llimphi standalone — framework UI soberano extraído del monorepo
1//! Clipboard abstracto. El editor no quiere acoplarse a un backend de
2//! SO concreto (X11 / Wayland / macOS / Windows), así que define el
3//! trait y entrega un mock para tests. La impl real (vía `arboard`)
4//! vive del lado del caller — típicamente la app embebida en
5//! `nada` o el visor del notebook.
6
7/// Backend de clipboard. `set` mete texto; `get` lo lee. Cualquiera de
8/// los dos puede fallar (sin display, headless CI, race con otro
9/// programa) — `None` / no-op silencioso es válido.
10pub trait Clipboard: Send {
11 fn get(&mut self) -> Option<String>;
12 fn set(&mut self, s: &str);
13}
14
15/// Clipboard de memoria — útil para tests y como fallback cuando el
16/// sistema no expone uno.
17#[derive(Debug, Default, Clone)]
18pub struct MemClipboard {
19 content: Option<String>,
20}
21
22impl MemClipboard {
23 pub fn new() -> Self {
24 Self::default()
25 }
26 pub fn with(s: impl Into<String>) -> Self {
27 Self { content: Some(s.into()) }
28 }
29}
30
31impl Clipboard for MemClipboard {
32 fn get(&mut self) -> Option<String> {
33 self.content.clone()
34 }
35 fn set(&mut self, s: &str) {
36 self.content = Some(s.to_owned());
37 }
38}
39
40/// "No clipboard" — `set` descarta, `get` devuelve `None`. Útil cuando
41/// el caller quiere desactivar copy/paste explícitamente.
42#[derive(Debug, Default, Clone, Copy)]
43pub struct NullClipboard;
44
45impl Clipboard for NullClipboard {
46 fn get(&mut self) -> Option<String> {
47 None
48 }
49 fn set(&mut self, _: &str) {}
50}