xonecas.io
8447
Co

conveyor / commit 4ea51c5

Helper modules, rune_kit and a shared image cache for widgets; keep drops the branch

A widgets/*.rs without pub const WIDGET is a helper module the widgets
share rather than a kind. Widgets get rune_kit (syntax highlighting,
Markdown, menus, tables...). cx.images() is one image cache per app,
made with the host's waker, so a decoded image redraws at once and
instances stop spawning decoder threads of their own. The library's
Cargo.lock is conveyor's now. Keep deletes the merged t-<id> branch.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 4ea51c519b42cbb35b3e50860fb5578509611dc0 parent c8081ea

13 files changed

Cargo.lock+29−0
@@ -611,6 +611,7 @@ version = "0.0.1"
611611 dependencies = [
612612 "conveyor-app",
613613 "rune",
614+ "rune-kit",
614615 ]
615616
616617 [[package]]
@@ -2394,6 +2395,17 @@ version = "1.0.18"
23942395 source = "registry+https://github.com/rust-lang/crates.io-index"
23952396 checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5"
23962397
2398+[[package]]
2399+name = "pulldown-cmark"
2400+version = "0.13.6"
2401+source = "registry+https://github.com/rust-lang/crates.io-index"
2402+checksum = "3db2be46835f013dd3f4fa7f5f7402c537787b54ebb6fe2b94bbdd7e2669bb7b"
2403+dependencies = [
2404+ "bitflags 2.13.2",
2405+ "memchr",
2406+ "unicase",
2407+]
2408+
23972409 [[package]]
23982410 name = "pxfm"
23992411 version = "0.1.30"
@@ -2643,6 +2655,17 @@ dependencies = [
26432655 "zeroize",
26442656 ]
26452657
2658+[[package]]
2659+name = "rune-kit"
2660+version = "0.0.1"
2661+source = "git+https://github.com/anomalyco/rune?rev=3ff3cc6152b9034a1d996e3a5575c51fab3b56b8#3ff3cc6152b9034a1d996e3a5575c51fab3b56b8"
2662+dependencies = [
2663+ "pulldown-cmark",
2664+ "rune",
2665+ "rune-motion",
2666+ "unicode-segmentation",
2667+]
2668+
26462669 [[package]]
26472670 name = "rune-motion"
26482671 version = "0.1.0"
@@ -3346,6 +3369,12 @@ dependencies = [
33463369 "windows-sys 0.61.2",
33473370 ]
33483371
3372+[[package]]
3373+name = "unicase"
3374+version = "2.10.0"
3375+source = "registry+https://github.com/rust-lang/crates.io-index"
3376+checksum = "357cc3acc6a036009fd6c973ed009037c732d60d0b4f6c673e9041497482a28f"
3377+
33493378 [[package]]
33503379 name = "unicode-ident"
33513380 version = "1.0.27"
Cargo.toml+2−0
@@ -8,6 +8,8 @@ resolver = "3"
88 serde = { version = "1", features = ["derive"] }
99 serde_json = "1"
1010 rune = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["native-file-dialog"] }
11+# Rune's components (syntax highlighting, Markdown, menus, tables, trees...), for widgets.
12+rune-kit = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["markdown"] }
1113
1214 [profile.release]
1315 incremental = true
crates/conveyor-app/src/app.rs+1−0
@@ -76,6 +76,7 @@ pub fn init() -> State {
7676
7777 /// Polls conveyord once a second on a thread. Every poll also re-renders, for clocks.
7878 pub fn setup(s: &mut State, waker: Waker) {
79+ s.live.set_waker(waker.clone());
7980 s.exe = std::env::current_exe().ok();
8081 s.built = s.exe.as_deref().and_then(mtime);
8182 let inbox = s.inbox.clone();
crates/conveyor-widgets/Cargo.toml+1−0
@@ -11,3 +11,4 @@ crate-type = ["dylib"]
1111 [dependencies]
1212 conveyor-app = { path = "../conveyor-app" }
1313 rune.workspace = true
14+rune-kit.workspace = true
crates/conveyor/src/library.rs+3−1
@@ -12,7 +12,7 @@ pub const BASE: &str = "trial:main";
1212 static BUILD: Mutex<()> = Mutex::new(());
1313
1414 /// Conveyor's side of the library: kept in step with the template on every start.
15-const OWNED: [&str; 8] = ["api.rs", "gen.rs", "CLAUDE.md", "Cargo.toml", "rust-toolchain.toml",
15+const OWNED: [&str; 9] = ["api.rs", "gen.rs", "CLAUDE.md", "Cargo.toml", "Cargo.lock", "rust-toolchain.toml",
1616 "preview/Cargo.toml", "preview/build.rs", "preview/src/main.rs"];
1717 const COMMIT: [&str; 4] = ["-c", "user.name=conveyor", "-c", "user.email=conveyor@localhost"];
1818
@@ -137,6 +137,8 @@ pub fn keep(id: u32) -> Result<(), String> {
137137 let _ = git(&lib, "", &["merge", "--abort"]);
138138 return Err(e);
139139 }
140+ // Merged: main has it, so the branch is only clutter.
141+ let _ = git(&lib, "", &["branch", "-d", &format!("t-{id}")]);
140142 store::set_state(SLUG, id, "done");
141143 store::event(SLUG, id, json!({"kind": "conveyor", "msg": "kept: merged into the library"}));
142144 trial(None)
crates/conveyor/src/library_tests.rs+3−2
@@ -65,11 +65,12 @@ fn trial_edges() {
6565 assert!(try_out(&p, c, &branch_c).unwrap_err().contains("conflicts"));
6666 assert!(has(&branch_b, "trial") && !has(&branch_c, "trial"));
6767
68- // A follow-up starts from the trial; keeping it keeps what it was built on.
68+ // A follow-up starts from the trial; keeping it keeps what it was built on, and drops its branch.
6969 let (d, branch_d) = build("trial", "d.rs", WIDGET);
7070 try_out(&p, d, &branch_d).unwrap();
71+ let (head_d, head_b) = (run(&paths::library(), &["rev-parse", &branch_d]), run(&paths::library(), &["rev-parse", &branch_b]));
7172 keep(d).unwrap();
72- assert!(state(d) == "done" && has(&branch_d, "main") && has(&branch_b, "main"));
73+ assert!(state(d) == "done" && has(head_d.trim(), "main") && has(head_b.trim(), "main") && !has(&branch_d, "main"));
7374 keep(b).unwrap();
7475 assert_eq!(state(b), "done");
7576
templates/library/CLAUDE.md+6−2
@@ -17,7 +17,9 @@ Read the words against that. "Make this purple" means the clicked kind. "Put a l
1717
1818 ## What's yours to change
1919
20-Only `widgets/`. Everything else is conveyor's (`api.rs`, `gen.rs`, `preview/`, this file), and a branch that changes it is rejected.
20+Only `widgets/`. Everything else is conveyor's (`api.rs`, `gen.rs`, `preview/`, `Cargo.*`, this file), and a branch that changes it is rejected.
21+
22+A file in `widgets/` with `pub const WIDGET` is a widget kind. One without it is a helper module the widgets share (`use super::highlight;`): put code two widgets need, or a big piece of one, there instead of growing a widget file.
2123
2224 ## A widget is a real program
2325
@@ -40,7 +42,9 @@ A widget is a struct with its own state that renders itself (`api::View`). Read
4042 - **Files.** `cx.dir` is the instance's own folder and survives reloads and restarts.
4143 - **Say what it is.** The first paragraph of a widget file's `//!` comment is its description: the library shows it to the user picking widgets (`cx.about(kind)`). One or two plain sentences on what it shows and does.
4244 - **A panic stops only that instance.** It draws a red card with the message until the next build, and the user can Ctrl+click it to have it fixed. If `root` or `status` stops, the app opens safe mode, where no widget runs.
43-- **Background work.** `std::thread`, and the system's programs with `std::process::Command` (`curl` for the network: std has no HTTPS). `rune::ImageCache` and `rune::Pixels` decode PNG and JPEG.
45+- **Background work.** `std::thread`, and the system's programs with `std::process::Command` (`curl` for the network: std has no HTTPS).
46+- **Images.** `cx.images()` is the app's image cache: `.load(bytes)`, `.file(path, ..)` and `.svg(..)` decode off the UI thread, and the app redraws when one is ready. Keep the handle in your state to load from handlers. Don't make your own `ImageCache`. `rune::Pixels` streams raw frames.
47+- **Components.** `rune_kit` is there too: syntax highlighting (`rune_kit::syntax`), Markdown, menus, popovers, tables, trees, dialogs, toasts and more. Use them before writing your own. Its source is next to rune's (`~/.cargo/git/checkouts/rune-*/*/crates/rune-kit/`).
4448
4549 ## When to block instead
4650
templates/library/Cargo.lock+29−0
@@ -2350,6 +2350,7 @@ name = "preview"
23502350 version = "0.0.0"
23512351 dependencies = [
23522352 "rune",
2353+ "rune-kit",
23532354 ]
23542355
23552356 [[package]]
@@ -2376,6 +2377,17 @@ version = "1.0.18"
23762377 source = "registry+https://github.com/rust-lang/crates.io-index"
23772378 checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5"
23782379
2380+[[package]]
2381+name = "pulldown-cmark"
2382+version = "0.13.6"
2383+source = "registry+https://github.com/rust-lang/crates.io-index"
2384+checksum = "3db2be46835f013dd3f4fa7f5f7402c537787b54ebb6fe2b94bbdd7e2669bb7b"
2385+dependencies = [
2386+ "bitflags 2.13.2",
2387+ "memchr",
2388+ "unicase",
2389+]
2390+
23792391 [[package]]
23802392 name = "pxfm"
23812393 version = "0.1.30"
@@ -2625,6 +2637,17 @@ dependencies = [
26252637 "zeroize",
26262638 ]
26272639
2640+[[package]]
2641+name = "rune-kit"
2642+version = "0.0.1"
2643+source = "git+https://github.com/anomalyco/rune?rev=3ff3cc6152b9034a1d996e3a5575c51fab3b56b8#3ff3cc6152b9034a1d996e3a5575c51fab3b56b8"
2644+dependencies = [
2645+ "pulldown-cmark",
2646+ "rune",
2647+ "rune-motion",
2648+ "unicode-segmentation",
2649+]
2650+
26282651 [[package]]
26292652 name = "rune-motion"
26302653 version = "0.1.0"
@@ -3328,6 +3351,12 @@ dependencies = [
33283351 "windows-sys 0.61.2",
33293352 ]
33303353
3354+[[package]]
3355+name = "unicase"
3356+version = "2.10.0"
3357+source = "registry+https://github.com/rust-lang/crates.io-index"
3358+checksum = "357cc3acc6a036009fd6c973ed009037c732d60d0b4f6c673e9041497482a28f"
3359+
33313360 [[package]]
33323361 name = "unicode-ident"
33333362 version = "1.0.27"
templates/library/api.rs+17−2
@@ -2,7 +2,7 @@
22 //! when it changes. Everything in widgets/ is the library's, starting with root.rs: the app
33 //! draws `root` and nothing else, so the whole UI is widgets.
44 use rune::{El, TextEdit, Tx, col};
5-use std::{any::Any, cell::{Cell, RefCell}, collections::{BTreeMap, BTreeSet, HashMap}, path::{Path, PathBuf}};
5+use std::{any::Any, cell::{Cell, OnceCell, RefCell}, rc::Rc, collections::{BTreeMap, BTreeSet, HashMap}, path::{Path, PathBuf}};
66
77 // ── What widgets read: conveyor's state ─────────────────────────────────────────────────────
88
@@ -121,6 +121,13 @@ impl Cx<'_> {
121121 self.live.render(kind, &format!("{}.{key}", self.id))
122122 }
123123
124+ /// The app's image cache: decodes off the UI thread and redraws when an image is ready.
125+ /// Keep the handle (`images: cx.images()`) to load from handlers too.
126+ pub fn images(&self) -> Rc<rune::ImageCache> {
127+ let live = self.live;
128+ live.images.get_or_init(|| Rc::new(rune::ImageCache::new(live.waker.clone()))).clone()
129+ }
130+
124131 /// What widget `kind` is, from the first paragraph of its file's `//!` comment.
125132 pub fn about(&self, kind: &str) -> &'static str {
126133 self.live.about.iter().find(|(n, _)| *n == kind).map_or("", |(_, a)| a)
@@ -269,6 +276,9 @@ pub struct Live {
269276 pub data: Data,
270277 kinds: Kinds,
271278 about: Abouts,
279+ /// The host's waker and the image cache made with it, shared by every widget.
280+ waker: rune::Waker,
281+ images: OnceCell<Rc<rune::ImageCache>>,
272282 /// Instances whose code panicked, with the message. They draw `stopped` until the next build.
273283 broken: RefCell<BTreeMap<String, String>>,
274284 base: PathBuf,
@@ -358,7 +368,7 @@ impl Live {
358368 // Instances that were keeping work going come back now, shown or not.
359369 let wanted: Vec<(String, String)> = std::fs::read_to_string(base.join("running.tsv")).unwrap_or_default().lines()
360370 .filter_map(|l| l.split_once('\t').map(|(id, kind)| (id.to_owned(), kind.to_owned()))).collect();
361- Live { data: Data::default(), kinds, about, broken: RefCell::new(BTreeMap::new()), base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
371+ Live { data: Data::default(), kinds, about, broken: RefCell::new(BTreeMap::new()), waker: std::sync::Arc::new(|| {}), images: OnceCell::new(), base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
362372 animate: Cell::new(false), outbox: vec![], spare: TextEdit::new(""), dirty: false,
363373 later: RefCell::new(vec![]), running: RefCell::new(BTreeSet::new()), kept: BTreeSet::new() }
364374 }
@@ -420,6 +430,11 @@ impl Live {
420430 self.make_wanted();
421431 }
422432
433+ /// How widgets wake the host from other threads (images decoded). Set it before rendering.
434+ pub fn set_waker(&mut self, waker: rune::Waker) {
435+ self.waker = waker;
436+ }
437+
423438 /// A shared value, as `cx.shared` reads it.
424439 pub fn shared(&self, key: &str) -> Option<&str> {
425440 self.shared.get(key).map(String::as_str)
templates/library/gen.rs+4−1
@@ -15,12 +15,15 @@ fn generate_widgets(lib: &std::path::Path, api: Option<&str>) {
1515 None => format!("#[allow(dead_code)]\n#[path = {:?}] pub mod api;\n", lib.join("api.rs")),
1616 };
1717 for n in &names { out += &format!("#[path = {:?}] pub mod {n};\n", dir.join(format!("{n}.rs"))); }
18+ // A file without `pub const WIDGET` is a helper module the widgets share, not a kind.
19+ let src = |n: &str| std::fs::read_to_string(dir.join(format!("{n}.rs"))).unwrap_or_default();
20+ names.retain(|n| src(n).contains("pub const WIDGET"));
1821 out += "pub const ALL: &[(&str, &api::Widget)] = &[";
1922 for n in &names { out += &format!("({n:?}, &{n}::WIDGET), "); }
2023 out += "];\npub const ABOUT: &[(&str, &str)] = &[";
2124 for n in &names {
2225 // The first paragraph of the file's `//!` comment.
23- let src = std::fs::read_to_string(dir.join(format!("{n}.rs"))).unwrap_or_default();
26+ let src = src(n);
2427 let about: Vec<&str> = src.lines().map_while(|l| l.strip_prefix("//!")).map(str::trim).take_while(|l| !l.is_empty()).collect();
2528 out += &format!("({n:?}, {:?}), ", about.join(" "));
2629 }
templates/library/preview/Cargo.toml+1−0
@@ -5,3 +5,4 @@ edition = "2024"
55
66 [dependencies]
77 rune = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["native-file-dialog"] }
8+rune-kit = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["markdown"] }
templates/library/preview/src/main.rs+1−1
@@ -133,5 +133,5 @@ fn poll(s: &mut State, _: f64, tx: &mut Tx) -> bool {
133133 }
134134
135135 fn main() {
136- rune::run(AppSpec { poll: Some(poll), ..AppSpec::new("preview", (1400.0, 900.0), init, view) });
136+ rune::run(AppSpec { poll: Some(poll), setup: Some(|s: &mut State, w| s.live.set_waker(w)), ..AppSpec::new("preview", (1400.0, 900.0), init, view) });
137137 }
templates/library/widgets/editor.rs+3−3
@@ -3,7 +3,7 @@
33 //! The project is the one whose desktop this card is on.
44 use super::{api::*, canvas};
55 use rune::{El, Family, Image, ImageCache, Key, KeyEvent, ScrollSpec, SurfaceFit, TextEdit, Tx, col, el, oklch, row, text, text_input, tok};
6-use std::{collections::{BTreeSet, HashMap}, path::{Path, PathBuf}, sync::Arc};
6+use std::{collections::{BTreeSet, HashMap}, path::{Path, PathBuf}, rc::Rc};
77
88 pub const WIDGET: Widget = Widget { title: "Editor", size: (860.0, 540.0), new: |cx| Box::new(Editor::load(cx)) };
99
@@ -32,7 +32,7 @@ pub struct Editor {
3232 text: TextEdit,
3333 saved: String,
3434 drafted: String,
35- images: ImageCache,
35+ images: Rc<ImageCache>,
3636 dir: PathBuf,
3737 }
3838
@@ -43,7 +43,7 @@ impl Editor {
4343 let mut lines = state.lines().map(PathBuf::from);
4444 let file = lines.next().filter(|p| !p.as_os_str().is_empty());
4545 let mut e = Editor { root: project_dir(cx), listings: HashMap::new(), listed_at: 0.0, expanded: lines.collect(),
46- file: None, content: Content::None, text: TextEdit::new(""), saved: String::new(), drafted: String::new(), images: ImageCache::new(Arc::new(|| {})), dir: cx.dir.clone() };
46+ file: None, content: Content::None, text: TextEdit::new(""), saved: String::new(), drafted: String::new(), images: cx.images(), dir: cx.dir.clone() };
4747 let draft = std::fs::read_to_string(e.dir.join("draft"));
4848 if let Some(f) = file { e.open(f) }
4949 if let (Content::Text, Ok(draft)) = (&e.content, draft) { e.text.text = draft }