Skip to content

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 →

Diff viewDiff view
  • 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 pz
from 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)

Two lines of context surround each change; changes further apart are split by ⋯.

Diff view: Changed linesDiff view: Changed lines
Changed lines
Code
pz.container(ui.diff_view({"path": "app.py", "old": "x = 1\ny = 2\n", "new": "x = 10\ny = 2\n"}),
width=300)
Diff view: New fileDiff view: New file
New file
Code
pz.container(ui.diff_view({"path": "main.py", "old": "", "new": "import pyzed as pz\n\npz.run(App)\n"}),
width=300)
Diff view: Removed linesDiff view: Removed lines
Removed lines
Code
pz.container(ui.diff_view({"path": "todo.txt", "old": "milk\neggs\nbread\n", "new": "milk\n"}),
width=300)
Diff view: Changes far apartDiff view: Changes far apart
Changes far apart
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)
Diff view: max_lines=4Diff view: max_lines=4
max_lines=4
Code
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)

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.

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.

Full reference →