diff

look

A file's diff.

Drawn

src/lib.rs+2 −1
@@ -12,3 +12,4 @@
fn total(rows: &[Row]) -> u64 {
- rows.len()
+ let n = rows.len();
+ n.try_into().unwrap_or(u64::MAX)
}

The sample

site/src/kinds.rs:432–498

fn others() -> Vec<Block> {
    let settings = Form::new(vec![
        picker("region", "Region", &["eu-west", "us-east"]),
        field("retries", "Retries", FieldValue::Number(3.into())),
        toggle("notify", "Notify", false),
    ])
    .id("settings")
    .action("save-settings");
    let hunk = Hunk {
        at: "@@ -12,3 +12,4 @@".into(),
        lines: vec![
            " fn total(rows: &[Row]) -> u64 {".into(),
            "-    rows.len()".into(),
            "+    let n = rows.len();".into(),
            "+    n.try_into().unwrap_or(u64::MAX)".into(),
            " }".into(),
        ],
    };
    let lane = |id: &str, title: &str, stage: &str, state: LaneState| Lane {
        id: id.into(),
        title: title.into(),
        stage: Some(stage.into()),
        state,
        ..Lane::default()
    };
    let island = Island::new(
        "x-chart",
        Fallback {
            title: "Downloads by week".into(),
            subtitle: Some("the chart needs JS; 1,204 last week".into()),
            tap: None,
        },
    )
    .id("chart")
    .events(vec!["pick".to_string()])
    .size(IslandSize {
        aspect: Some("16:7".into()),
        ..IslandSize::default()
    });
    vec![
        b!(Config(settings)),
        b!(Secret(
            Secret::new("token", "save-token")
                .id("token")
                .label("API token")
                .placeholder("paste a token")
                .set(true)
        )),
        b!(Diff(Diff::new("src/lib.rs", vec![hunk]).id("change").summary("+2 −1"))),
        b!(Editor(
            Editor::new("notes", "# Notes\n\nShip on Friday.\nCheck the bench\n", "save-notes")
                .id("editor")
                .errors(vec![LineError {
                    line: 4,
                    message: "a line ends with no full stop".into(),
                }])
        )),
        b!(Web(Web::new("media/sample.svg", 240_u32).id("doc"))),
        b!(Scene(Scene::new().id("crew").label("Workers").lanes(vec![
            lane("w1", "build", "compile", LaneState::Working),
            lane("w2", "review", "read the diff", LaneState::Needs),
            lane("w3", "docs", "publish", LaneState::Done),
            lane("w4", "bench", "wait", LaneState::Idle),
        ]))),
        b!(Island(island)),
    ]
}
{
  "blocks": [
    {
      "fallback": {
        "title": "src/lib.rs"
      },
      "file": "src/lib.rs",
      "hunks": [
        {
          "at": "@@ -12,3 +12,4 @@",
          "lines": [
            " fn total(rows: &[Row]) -> u64 {",
            "-    rows.len()",
            "+    let n = rows.len();",
            "+    n.try_into().unwrap_or(u64::MAX)",
            " }"
          ]
        }
      ],
      "id": "change",
      "summary": "+2 −1",
      "type": "diff"
    }
  ],
  "fallback": {
    "title": "screen"
  },
  "id": "diff",
  "type": "screen"
}

Its fallback

What a renderer without diff draws: a row from the fallback the block carries.
src/lib.rs

Style hooks

.b-diffthe block
[data-block=diff]every block of the kind
[data-id=change]this one block
Every page here is a blocks Screen, written by site::page: no hand-written HTML. Source: https://github.com/jirathip-dev/blocks