Diff view
ui.diff_view(diff) shows an edit: the file’s name, then the lines that changed (added in green, removed in red) with two lines of context around each change; changes far apart are split by ⋯. diff is a dict with path, old and new, the whole texts before and after, and max_lines limits how many lines show before … N more lines. It is what a Tool call shows for the edits it made.
ui.diff_view · Category: AI agents · Full reference →


old = "def save(path):\n data = load()\n write(path, data)\n return True\n"new = "def save(path, data):\n write(path, data)\n log(path)\n return True\n"pz.container(ui.diff_view({"path": "app/storage.py", "old": old, "new": new}), width=420)When to use
Section titled “When to use”- To show what an agent or a tool changed in a file.
- To review a change before saving it, next to Keep and Reject buttons.
- For the counts alone (
+12 −3), use Diff stat.
import pyzed as pzfrom pyzed import ui
old = "def save(path):\n data = load()\n write(path, data)\n return True\n"new = "def save(path, data):\n write(path, data)\n log(path)\n return True\n"pz.container(ui.diff_view({"path": "app/storage.py", "old": old, "new": new}), width=420)Variants
Section titled “Variants”Content
Section titled “Content”Two lines of context surround each change; changes further apart are split by ⋯.


Code
pz.container(ui.diff_view({"path": "app.py", "old": "x = 1\ny = 2\n", "new": "x = 10\ny = 2\n"}), width=300)

Code
pz.container(ui.diff_view({"path": "main.py", "old": "", "new": "import pyzed as pz\n\npz.run(App)\n"}), width=300)

Code
pz.container(ui.diff_view({"path": "todo.txt", "old": "milk\neggs\nbread\n", "new": "milk\n"}), width=300)

Code
old = "".join(f"line {i}\n" for i in range(1, 13))new = old.replace("line 2\n", "line two\n").replace("line 11\n", "")pz.container(ui.diff_view({"path": "notes.txt", "old": old, "new": new}), width=300)

max_lines=4Code
new = "".join(f"item {i}\n" for i in range(1, 11))pz.container(ui.diff_view({"path": "list.txt", "old": "", "new": new}, max_lines=4), width=300)Events
Section titled “Events”Diff view has no events of its own: it shows what you give it. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
Properties and API
Section titled “Properties and API”ui.diff_view
Section titled “ui.diff_view”diff_view(diff, *, theme=None, max_lines=120)An edit as Zed shows it in a thread: the file’s name, then the changed lines (green added, red removed) with a few lines around them.
| Property | Default | Description |
|---|---|---|
diff |
required | A dict with path, old and new (the texts before and after). |
theme |
None |
Theme. |
max_lines |
120 |
Lines shown before … N more lines. |