tawasuyu

tawasuyu/llimphi

Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.

Rust 660Markdown 302TOML 157RON 312382 Definitions

⎇ main widgets/text-editor-core/src/clipboard.rs Rust · 53 lines · 1.5 KB History Who touched what raw

chore: refresco desde el monorepo — vello 0.9 / wgpu 29, 120 miembros d251eb32b · Sergio ·

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
7use alloc::borrow::ToOwned;
8use alloc::string::String;
9
10/// Backend de clipboard. `set` mete texto; `get` lo lee. Cualquiera de
11/// los dos puede fallar (sin display, headless CI, race con otro
12/// programa) — `None` / no-op silencioso es válido.
13pub trait Clipboard: Send {
14    fn get(&mut self) -> Option<String>;
15    fn set(&mut self, s: &str);
16}
17
18/// Clipboard de memoria — útil para tests y como fallback cuando el
19/// sistema no expone uno.
20#[derive(Debug, Default, Clone)]
21pub struct MemClipboard {
22    content: Option<String>,
23}
24
25impl MemClipboard {
26    pub fn new() -> Self {
27        Self::default()
28    }
29    pub fn with(s: impl Into<String>) -> Self {
30        Self { content: Some(s.into()) }
31    }
32}
33
34impl Clipboard for MemClipboard {
35    fn get(&mut self) -> Option<String> {
36        self.content.clone()
37    }
38    fn set(&mut self, s: &str) {
39        self.content = Some(s.to_owned());
40    }
41}
42
43/// "No clipboard" — `set` descarta, `get` devuelve `None`. Útil cuando
44/// el caller quiere desactivar copy/paste explícitamente.
45#[derive(Debug, Default, Clone, Copy)]
46pub struct NullClipboard;
47
48impl Clipboard for NullClipboard {
49    fn get(&mut self) -> Option<String> {
50        None
51    }
52    fn set(&mut self, _: &str) {}
53}