git clone https://garage44.eu/jeroen/pinnacle.gitcartopolis-agent · 2026-11-30T15:37:25Z
feat(filer): open pictures in Files, and say when nothing opens a file Tapping a PNG, JPEG, GIF or WebP in Files now shows the picture, fitted to the file's pane (a <canvas> the app paints, as Paint does), with its size in pixels beside the file's. It is told by its first bytes, decoded once by pinnacle_media::picture (Wil) and kept until another file is opened or it changes. A file that starts like a picture but will not decode says so; one that is neither text nor a picture says that nothing here opens this kind of file, in place of "no app here opens it yet".
docs/full-os.md | 4 +-
docs/roadmap.md | 2 +-
locale/src/nl.rs | 5 ++-
programs/src/bin/filer.rs | 109 ++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 107 insertions(+), 13 deletions(-)
diff --git a/docs/full-os.md b/docs/full-os.md
index 6a8d021..b99b439 100644
--- a/docs/full-os.md
+++ b/docs/full-os.md
@@ -87,7 +87,7 @@ come first, because several programs share each one.
| Library | Need | Used by | Where |
|---|---|---|---|
| Compression: deflate/inflate, gzip, zip | 1 | PNG, PDF, the web (gzip), mail attachments, backups, Store packages | pinnacle crate, or the codecs project below |
-| Image formats: PNG, JPEG, WebP, GIF; later AVIF | 1 | Photos, the browser, mail, Messages, Files' previews | **new project** (codecs) |
+| Image formats: PNG, JPEG, WebP, GIF; later AVIF | 1 | Photos, the browser, mail, Messages, Files (pictures opened since s938, `media::picture`) | **Wil** (`jeroen/wil`), the codecs project |
| Audio formats: Opus, FLAC, Vorbis, MP3, AAC | 2 | Music, Calls (Opus would replace ADPCM), the browser | **new project** (codecs) |
| Video formats: AV1 and VP9 first, H.264 for the existing web | 2 | Video player, the browser, Calls (now an own codec, `media/src/video.rs`) | **new project** (codecs); a large one |
| HTML and CSS layout | 1 | browser, mail, help pages | **new project** (browser engine) |
@@ -102,7 +102,7 @@ come first, because several programs share each one.
| **Mail** (IMAP + SMTP, or JMAP) | 1 | **Kees** (`jeroen/kees`, 2026-11-29): IMAP + SMTP, plain text | the project **Kees**, with Calendar; on TLS, `rt::net`, Mithril; shows HTML mail as text until the browser engine's layout can show it. |
| **Calendar** (CalDAV, `.ics` invites) | 1 | **Kees**: CalDAV, invites by mail answered | in Kees, together with Mail (one account sync, one engine). |
| Contacts sync (CardDAV) | 2 | **Kees** syncs address books into Contacts by UID | in Kees; Contacts' own edits do not go back to the server yet |
-| **Photos**: view, scroll, share | 1 | Paint draws; nothing shows a photo | pinnacle system program, on codecs |
+| **Photos**: view, scroll, share | 1 | Files opens a picture, fitted to its pane (s938); no app of its own, no zoom, scrolling or sharing | pinnacle system program, on codecs |
| **Camera** | 1 (phone) | Nothing | pinnacle, after the camera driver |
| **Music and video player** | 2 | Nothing plays a file | pinnacle program, on codecs and `rt::audio` |
| **PDF reader** | 1 | Nothing | **new project** (the library) and its viewer |
diff --git a/docs/roadmap.md b/docs/roadmap.md
index 79fbd0d..cf664b4 100644
--- a/docs/roadmap.md
+++ b/docs/roadmap.md
@@ -50,7 +50,7 @@ What is still missing for daily use, and the projects it will take, is in
| A file system that survives power cuts: every change one transaction, contents copy-on-write, the inode table and bitmap through a journal with a checksum; a check of the whole disk at mount; tested by cutting the power after every one of a run's writes | Done |
| Files of up to 4 GiB, read and written a range at a time (READ_AT, WRITE_AT), with holes; the time each last changed (STAT); one call copies at most 16 MiB | Done |
| Files of up to 4 TiB (a third, three-deep tree of block tables); a large file's space freed after its removal or replacement, from its end down in transactions the journal holds, finished at mount after a power cut; taking a free block in constant time (next-fit, a count of free blocks kept); a directory entry written in its own slot, not the whole directory again | Done (disks up to 16 TiB: block numbers are 32 bits) |
-| Files: the person's folders by tapping (`programs/src/bin/filer.rs`, a system program beside the Terminal): their home and each app's folder under the app's name, a folder or a file opened with a tap (a file's text, or that it is not text), a file moved into another folder (Move, the folder, Move here) or deleted on a second tap; what the p2p service keeps (identity, messages, contacts) not shown; `cargo xtask files-demo` | Done (no new folder, renaming or deleting a folder yet; files open as text only; nothing comes onto the device or leaves it but through an app's folder) |
+| Files: the person's folders by tapping (`programs/src/bin/filer.rs`, a system program beside the Terminal): their home and each app's folder under the app's name, a folder or a file opened with a tap (a file's text; a picture, PNG, JPEG, GIF or WebP told by its first bytes and decoded by Wil, fitted to the pane; or that nothing here opens it), a file moved into another folder (Move, the folder, Move here) or deleted on a second tap; what the p2p service keeps (identity, messages, contacts) not shown; `cargo xtask files-demo` | Done (no new folder, renaming or deleting a folder yet; pictures are not zoomed and nothing else opens yet (no PDF, sound or video); nothing comes onto the device or leaves it but through an app's folder) |
| A code editor, Fien (`jeroen/fien`, a system program beside Files): many cursors, undo by edit, colour for Rust and Frits, long lines wrapped, a finger's selection by handles; a Frits script checked against the terminal's platform as typing pauses and its names completed; Files opens a text file in it (Edit, through `system-fien`); Share edits a text with a contact at the same time over the p2p sessions (`fien`, offered in Settings, Remote access), each seeing the other's cursor | Done (one contact at a time; an edit from the other forgets the undo history; Rust is coloured, not checked) |
| Mail, calendar and contacts, Kees (`jeroen/kees`, a system program beside Fien): one account and one login for all three, its servers guessed from the address (a known provider's, or the usual names); IMAP and SMTP (TLS, or STARTTLS) over Pinnacle's TLS, every folder's newest 500 messages, read as plain text (HTML shown as its text), with files to save in its folder; replies, forwards, addresses completed from the address books, mail written offline sent with the next sync; CalDAV calendars a week at a time, with time zones and repeats, events made, changed and deleted (a change made elsewhere refused, not overwritten); invites by mail accepted, maybe or declined (the answer mailed to the organiser, the event put in the calendar), cancels and answers applied; CardDAV address books synced into Contacts by UID. The engine on a thread of its own, a sync every five minutes; the self-check syncs a whole account against the provider in memory (`kees ok`); `cargo xtask kees-demo` | Done (passwords only: no OAuth for Google's calendars or Outlook.com; no HTML layout, no new attachments, no IMAP IDLE; repeating events are shown and their words changed, not made; the zone is `system:/locale/zone` when Kees knows it (Europe's and four American ones), else Amsterdam) |
| Text input: an on-screen keyboard; a notes app | Done (Notes: a file a note in its own folder, saved half a second after the last key; the caret put down by a tap or moved by the arrow keys, text typed, deleted or pasted where it is) |
diff --git a/locale/src/nl.rs b/locale/src/nl.rs
index 949a046..a517630 100644
--- a/locale/src/nl.rs
+++ b/locale/src/nl.rs
@@ -3,7 +3,7 @@
//! missing here fails `every_text_the_programs_ask_for_is_translated`.
#[rustfmt::skip]
-pub static TEXTS: [(&str, &str); 421] = [
+pub static TEXTS: [(&str, &str); 422] = [
("+ New note", "+ Nieuwe notitie"),
(", kept", ", bewaard"),
("1 note", "1 notitie"),
@@ -126,6 +126,7 @@ pub static TEXTS: [(&str, &str); 421] = [
("Installed, not offered now", "Geïnstalleerd, nu niet aangeboden"),
("Installing…", "Installeren…"),
("It could not be read", "Het kon niet worden gelezen"),
+ ("It looks like a picture, but it could not be shown", "Het lijkt een afbeelding, maar kon niet worden getoond"),
("It opens your data each time the device starts, and unlocks the screen. At least eight characters; nobody can recover it.", "Het opent je gegevens telkens als het apparaat start, en ontgrendelt het scherm. Minstens acht tekens; niemand kan het terughalen."),
("It rings while Clock is open, in front or not.", "Hij gaat af zolang Klok open is, op de voorgrond of niet."),
("Join", "Verbinden"),
@@ -200,9 +201,9 @@ pub static TEXTS: [(&str, &str); 421] = [
("Not online: calling by phone…", "Niet online: bellen via de telefoon…"),
("Not reachable", "Niet bereikbaar"),
("Not sent", "Niet verstuurd"),
- ("Not text: no app here opens it yet", "Geen tekst: nog geen app hier opent het"),
("Not yet", "Nog niet"),
("Notes", "Notities"),
+ ("Nothing here opens this kind of file", "Niets hier opent dit soort bestand"),
("Nothing here yet: files moved here from an app's folder stay here", "Nog niets hier: bestanden die je hierheen verplaatst uit de map van een app, blijven hier"),
("Nothing selected", "Niets geselecteerd"),
("Notifications", "Meldingen"),
diff --git a/programs/src/bin/filer.rs b/programs/src/bin/filer.rs
index 541e856..c3bc981 100644
--- a/programs/src/bin/filer.rs
+++ b/programs/src/bin/filer.rs
@@ -1,7 +1,9 @@
//! Files: the person's folders, looked through by tapping. The first page
//! has the files and folders of their home (the data vault once it is open)
//! and each app's own folder, under the app's name; a folder opens with a
-//! tap, a file too: its text, or what it is when it is not text. An open
+//! tap, a file too: its text, a picture (PNG, JPEG, GIF, WebP, told by its
+//! first bytes and decoded by Wil) fitted to the pane, or that nothing here
+//! opens it. An open
//! file is moved or copied into another folder (Move or Copy, then the
//! folder, then "Move here" or "Copy here"), renamed, or deleted once the
//! person says so a second time. A folder gets new folders in it, and one
@@ -24,7 +26,9 @@ extern crate alloc;
use alloc::string::String;
use alloc::vec::Vec;
+use pinnacle_gfx::{Canvas, Rect};
use pinnacle_locale::{fill, t, tf};
+use pinnacle_media::picture::{self, Picture};
use pinnacle_rt::fs;
use pinnacle_ui::command::{copy_file, home, size, when};
use pinnacle_ui::layout::notes;
@@ -244,7 +248,9 @@ fn page_of(place: &Place, first: bool) -> Page {
/// An opened file, as shown.
enum Shown {
Text(String, bool),
- Binary,
+ Picture,
+ /// Neither text nor a picture: nothing here opens it.
+ Nothing,
Unreadable,
}
@@ -252,6 +258,9 @@ fn show(e: &Entry) -> Shown {
let Some(data) = fs::read_at(&e.path, 0, (e.size as usize).min(SHOW_MAX)) else {
return Shown::Unreadable;
};
+ if picture::sniff(&data).is_some() {
+ return Shown::Picture;
+ }
match core::str::from_utf8(&data) {
Ok(text) if !text.contains('\0') => Shown::Text(text.into(), e.size as usize > SHOW_MAX),
// Cut mid-character at the limit: what came before it.
@@ -259,7 +268,30 @@ fn show(e: &Entry) -> Shown {
let text = core::str::from_utf8(&data[..err.valid_up_to()]).unwrap_or_default();
Shown::Text(text.into(), true)
}
- _ => Shown::Binary,
+ _ => Shown::Nothing,
+ }
+}
+
+/// The opened picture, decoded once: which file it is (its path, size and
+/// change), and the picture or why it could not be shown.
+type Decoded = ((String, u64, u64), Result<Picture, ()>);
+
+/// The picture in `e`, a file that starts like one.
+fn decode(e: &Entry) -> Result<Picture, ()> {
+ if e.size > picture::FILE_MAX {
+ pinnacle_rt::println!("filer: {} is too large to show", e.path);
+ return Err(());
+ }
+ let data = fs::read_at(&e.path, 0, e.size as usize).ok_or(())?;
+ match Picture::decode(&data) {
+ Ok(p) => {
+ pinnacle_rt::println!("filer: showing {} {}x{}", e.path, p.width(), p.height());
+ Ok(p)
+ }
+ Err(err) => {
+ pinnacle_rt::println!("filer: {} could not be shown: {err}", e.path);
+ Err(())
+ }
}
}
@@ -425,9 +457,31 @@ struct Model {
name: Signal<String>,
/// What the last action did, or why it could not.
said: String,
+ /// The opened file's picture, when it is one.
+ picture: Option<Decoded>,
}
impl Model {
+ /// Decodes the opened file's picture, when it is one not decoded yet
+ /// (or changed since); lets go of the last one otherwise.
+ fn decode_opened(&mut self) {
+ let Some(e) = self.opened().filter(|e| matches!(show(e), Shown::Picture)) else {
+ self.picture = None;
+ return;
+ };
+ let key = (e.path.clone(), e.size, e.modified);
+ if self.picture.as_ref().is_none_or(|(k, _)| *k != key) {
+ // The last one let go of first: two photos need not fit at once.
+ self.picture = None;
+ self.picture = Some((key, decode(&e)));
+ }
+ }
+
+ /// The opened picture, when it could be decoded.
+ fn shown_picture(&self) -> Option<&Picture> {
+ self.picture.as_ref().and_then(|(_, p)| p.as_ref().ok())
+ }
+
fn place(&self) -> &Place {
self.places.last().expect("the first page")
}
@@ -988,9 +1042,21 @@ fn file_pane(m: &Model, e: &Entry, both: bool, tapped: &Signal<Option<Tap>>) ->
}
text.into_view()
}
- Shown::Binary => el("p")
+ // Drawn by the app into the canvas's place (`draw`), fitted to it.
+ Shown::Picture if m.shown_picture().is_some() => el("canvas")
+ .attr("data-name", "picture")
+ .attr("data-revision", e.path.clone())
+ .attr("role", "img")
+ .attr("aria-label", e.label.clone())
+ .attr("style", "flex: 1; display: block; min-height: 240px")
+ .into_view(),
+ Shown::Picture => el("p")
+ .attr("style", "color: var(--m-text-dim)")
+ .child(t("It looks like a picture, but it could not be shown"))
+ .into_view(),
+ Shown::Nothing => el("p")
.attr("style", "color: var(--m-text-dim)")
- .child(t("Not text: no app here opens it yet"))
+ .child(t("Nothing here opens this kind of file"))
.into_view(),
Shown::Unreadable => el("p")
.attr("style", "color: var(--m-text-dim)")
@@ -1007,7 +1073,7 @@ fn file_pane(m: &Model, e: &Entry, both: bool, tapped: &Signal<Option<Tap>>) ->
.child(
el("p")
.attr("style", "margin: 0; color: var(--m-text-dim)")
- .child(tf("{} · in {}", &[&facts(e), &m.place_label()])),
+ .child(tf("{} · in {}", &[&about_file(m, e), &m.place_label()])),
)
.child(buttons);
let naming = matches!(m.naming, Some(Naming::File(_)));
@@ -1021,6 +1087,15 @@ fn file_pane(m: &Model, e: &Entry, both: bool, tapped: &Signal<Option<Tap>>) ->
pane.child(body).into_view()
}
+/// What the opened file is: a picture's size in pixels first, then its
+/// size and when it changed.
+fn about_file(m: &Model, e: &Entry) -> String {
+ match m.shown_picture() {
+ Some(p) => alloc::format!("{} × {} · {}", p.width(), p.height(), facts(e)),
+ None => facts(e),
+ }
+}
+
/// The folder and the opened file side by side on a wide window, one of
/// them on a narrow one.
fn page(m: &Model, both: bool, tapped: &Signal<Option<Tap>>) -> View {
@@ -1051,6 +1126,22 @@ fn page(m: &Model, both: bool, tapped: &Signal<Option<Tap>>) -> View {
root.into_view()
}
+/// Draws the window (all of it, or what changed), the opened picture in its
+/// canvas's place, fitted to it.
+fn draw(screen: &mut Screen, canvas: &mut Canvas, all: bool, m: &mut Model) -> Option<Rect> {
+ screen.draw_with(canvas, all, &mut |name, canvas, rect| {
+ let Some((_, Ok(p))) = &mut m.picture else {
+ return;
+ };
+ if name != "picture" || rect.width <= 0 || rect.height <= 0 {
+ return;
+ }
+ let f = p.fit(rect.width as u32, rect.height as u32, theme::SURFACE.0);
+ let (x, y) = (rect.x + f.x as i32, rect.y + f.y as i32);
+ canvas.blit(&f.pixels, f.width as i32, f.height as i32, x, y);
+ })
+}
+
/// Opens `path` in Fien: starts it (or brings it to the front) and asks
/// its service for the file, waiting a little for a Fien just started.
fn edit_in_fien(app: &App, path: &str) {
@@ -1089,6 +1180,7 @@ fn main(_argument: u64) -> u64 {
naming: None,
name: signal(String::new()),
said: String::new(),
+ picture: None,
};
let mut screen = Screen::new(app.width, app.height);
let tapped: Signal<Option<Tap>> = signal(None);
@@ -1102,8 +1194,9 @@ fn main(_argument: u64) -> u64 {
if redraw {
screen.resize(app.width, app.height);
screen.clear();
+ m.decode_opened();
screen.mount(page(&m, notes::two_panes(app.width as i32), &tapped));
- screen.draw(&mut app.canvas(), true);
+ draw(&mut screen, &mut app.canvas(), true, &mut m);
app.present_all();
screen.announce("filer: button ");
redraw = false;
@@ -1144,7 +1237,7 @@ fn main(_argument: u64) -> u64 {
Event::Closed => return 0,
_ => {}
}
- if !redraw && let Some(area) = screen.draw(&mut app.canvas(), false) {
+ if !redraw && let Some(area) = draw(&mut screen, &mut app.canvas(), false, &mut m) {
app.present(area);
}
}