Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HTTP, GraphQL and WebSocket. Collections, environments and variables, a history

## Notes and snippets

![The notes: by date, as a board of folders, a search quoting the line that matched, the facets, a selection, a snippet with its fields and their form, its history, a formatted Note and its presentation, a todo list, a Calcul sheet, the palette, the trash, and the light theme](docs/tour-notes.gif)
![The notes: by date, as a board of folders, a search quoting the line that matched, the facets, a selection, a snippet with its fields and their form, its history, a formatted Note and its presentation, a todo list, a Calcul sheet, the palette and the trash](docs/tour-notes.gif)

- **Three kinds of note.** Snippets highlighted in twenty-six languages and formatted with Prettier; Notes written formatted — headings, lists, checkboxes, tables, code blocks — and stored as Markdown; todo lists you tick off.
- **`{{fields}}`.** `ssh -p {{port=22}} {{user}}@{{host}}` asks for its values before it reaches the clipboard, with defaults you set once.
Expand Down Expand Up @@ -91,7 +91,7 @@ Every tool runs on your machine and calls nothing. Search them, star the ones yo

## API client

![The API client: its collections, an HTTP request, a GraphQL request, a WebSocket, the environments, the code generated from a request, and the light theme](docs/tour-http.gif)
![The API client: its collections, an HTTP request, a GraphQL request, a WebSocket, the environments and the code generated from a request](docs/tour-http.gif)

- **HTTP and GraphQL** requests in tabs, with bodies, authentication and cookies; a GraphQL answer's errors read apart from its data.
- **WebSocket** connections with a live log, and messages kept to send again.
Expand Down
2 changes: 2 additions & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ puffin_http = { workspace = true, optional = true }
winit.workspace = true

[dev-dependencies]
# `examples/tours.rs`, which assembles the README's tours, and their test.
image.workspace = true
# `examples/icons.rs`, which draws the icons.
resvg.workspace = true
tempfile.workspace = true
Expand Down
148 changes: 148 additions & 0 deletions crates/app/examples/tours.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//! Assembles the README's tours from the screens `app::screens` draws:
//! `DEVNOTES_SCREENS=<dir> cargo test -p ui --lib app::screens`, then
//! `cargo run -p app --example tours -- <dir>`, which writes `docs/tour-*.gif`.
//!
//! One theme throughout, the dark one: a loop that ends on a light frame flashes.

use std::collections::HashMap;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::time::Duration;

use image::codecs::gif::{GifEncoder, Repeat};
use image::{Delay, Frame, Rgba, RgbaImage};

/// A tour and its screens, in the order of the README's caption.
const TOURS: [(&str, &[&str]); 3] = [
(
"notes",
&[
"notes-list",
"notes-board",
"notes-search",
"notes-facets",
"notes-selection",
"editor-snippet-fields",
"notes-fields-form",
"editor-snippet-revisions",
"editor-note",
"editor-note-presentation",
"editor-checklist",
"editor-calc",
"notes-palette",
"notes-trash",
],
),
(
"tools",
&[
"tools-home",
"tool-jwt",
"tool-json-generator",
"tool-diff",
"tool-hash",
"tool-password",
"tool-dates",
"tool-zones",
"tool-cron",
"tool-cidr",
"tool-colour",
"tool-qr",
"tool-identity",
"tool-http-status",
],
),
(
"http",
&[
"http-home",
"http-request",
"http-graphql",
"http-websocket",
"http-environments",
"http-code",
],
),
];

const SHOWN: Duration = Duration::from_secs(2);
/// What a GIF holds.
const COLOURS: usize = 256;

fn main() {
let screens = std::env::args_os().nth(1).map(PathBuf::from);
let screens = screens.expect("the folder the screens were drawn in");
let docs = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../docs");
for (name, frames) in TOURS {
let path = docs.join(format!("tour-{name}.gif"));
let frames: Vec<RgbaImage> = frames.iter().map(|one| screen(&screens, one)).collect();
write(&path, &frames);
let bytes = std::fs::metadata(&path).expect("written").len();
println!("{} {} frames, {bytes} bytes", path.display(), frames.len());
}
}

fn screen(screens: &Path, name: &str) -> RgbaImage {
let path = screens.join(format!("{name}--dark.png"));
let image = image::open(&path).unwrap_or_else(|error| panic!("{}: {error}", path.display()));
image.into_rgba8()
}

/// One palette for the whole loop, or a ground would change its shade from a frame to the next.
/// ⚠️ Each frame whole: `image` writes frames that clear what is under them.
fn write(path: &Path, frames: &[RgbaImage]) {
let palette = palette(frames);
let mut nearest = HashMap::new();
let file = File::create(path).unwrap_or_else(|error| panic!("{}: {error}", path.display()));
let mut encoder = GifEncoder::new(file);
encoder.set_repeat(Repeat::Infinite).expect("a loop");
for frame in frames {
let mut reduced = frame.clone();
for pixel in reduced.pixels_mut() {
*pixel = *nearest
.entry(*pixel)
.or_insert_with(|| closest(&palette, *pixel));
}
let delay = Delay::from_saturating_duration(SHOWN);
encoder
.encode_frame(Frame::from_parts(reduced, 0, 0, delay))
.expect("a frame");
}
}

/// The colours most seen, each far enough from the ones before it: grounds and inks stay exact,
/// and what is left goes to the edges of the letters.
fn palette(frames: &[RgbaImage]) -> Vec<Rgba<u8>> {
let mut seen: HashMap<Rgba<u8>, u32> = HashMap::new();
for pixel in frames.iter().flat_map(RgbaImage::pixels) {
*seen.entry(*pixel).or_default() += 1;
}
let mut seen: Vec<(Rgba<u8>, u32)> = seen.into_iter().collect();
seen.sort_unstable_by_key(|(colour, count)| (std::cmp::Reverse(*count), colour.0));
let mut apart = 0;
loop {
let mut kept: Vec<Rgba<u8>> = Vec::new();
for (colour, _) in &seen {
if kept.iter().all(|one| distance(*one, *colour) >= apart) {
kept.push(*colour);
}
if kept.len() > COLOURS {
break;
}
}
if kept.len() <= COLOURS {
return kept;
}
apart += 1;
}
}

fn closest(palette: &[Rgba<u8>], colour: Rgba<u8>) -> Rgba<u8> {
let by_distance = palette.iter().min_by_key(|one| distance(**one, colour));
*by_distance.expect("a frame has colours")
}

fn distance(a: Rgba<u8>, b: Rgba<u8>) -> u32 {
let channels = a.0.iter().zip(b.0);
channels.map(|(a, b)| u32::from(a.abs_diff(b)).pow(2)).sum()
}
35 changes: 35 additions & 0 deletions crates/app/tests/tours.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! The README's tours: one theme throughout, and light enough for a page.

use std::path::Path;

use image::AnimationDecoder;
use image::codecs::gif::GifDecoder;

const HEAVIEST: usize = 1_000_000;
/// In the title bar's corner, clear of everything on it: its ground, in every frame but a
/// presentation's, whose ground is as dark.
const GROUND: (u32, u32) = (3, 3);
const DARK: u8 = 40;

#[test]
fn every_frame_of_every_tour_is_dark_and_each_file_under_a_megabyte() {
for name in ["notes", "tools", "http"] {
let path = Path::new(env!("CARGO_MANIFEST_DIR"));
let path = path.join(format!("../../docs/tour-{name}.gif"));
let bytes = std::fs::read(&path).unwrap();
assert!(bytes.len() < HEAVIEST, "{name}: {} bytes", bytes.len());

let decoder = GifDecoder::new(std::io::Cursor::new(bytes)).unwrap();
let mut drawn = 0;
for frame in decoder.into_frames() {
let frame = frame.unwrap();
let whole = frame.buffer().pixels().all(|pixel| pixel.0[3] == 255);
assert!(whole, "{name}, frame {drawn}: seen through");
let ground = frame.buffer().get_pixel(GROUND.0, GROUND.1);
let brightest = ground.0[..3].iter().max().unwrap();
assert!(*brightest < DARK, "{name}, frame {drawn}: {ground:?}");
drawn += 1;
}
assert!(drawn > 5, "{name}: {drawn} frames");
}
}
7 changes: 5 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6597,8 +6597,11 @@ pixels: the geometry and SSIM scoring the plan describes are postponed (D24).
`app::screens` replays the reference's own screens, its data, gestures, file names and window
sizes: `DEVNOTES_SCREENS=<dir> cargo test -p ui --lib app::screens` writes the PNGs to set beside
the `angular-reference` zip, one profile copy a screen since a board shown or a rail put away is
remembered. Without the variable it does nothing, and CI does not set it. The three tours of the README (`docs/tour-notes.gif`,
`docs/tour-tools.gif`, `docs/tour-http.gif`) are frames of those screens, two seconds each.
remembered. Without the variable it does nothing, and CI does not set it. The three tours of the
README (`docs/tour-notes.gif`, `docs/tour-tools.gif`, `docs/tour-http.gif`) are frames of those
screens, two seconds each, assembled by `cargo run -p app --example tours -- <dir>`: in the dark
theme throughout, with one palette a loop. A frame of another theme, or a file of a megabyte,
fails `crates/app/tests/tours.rs`.

### The scenarios, on the assembled window

Expand Down
Binary file modified docs/tour-http.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tour-notes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tour-tools.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading