Edits bar
ui.EditsBar is a component that lists the files an agent changed: 3 files changed with the lines added and removed, Reject all and Keep all. Clicking the title unfolds one row per file with its diff stat and buttons to reject or keep that file alone; clicking a file’s name reports on_open. files are dicts or objects with path and optional added and removed line counts. The file events (on_keep_file, on_reject_file, on_open) carry the path in event.value.
ui.EditsBar · Category: AI agents · Full reference →


pz.container(ui.EditsBar(files=[ {"path": "app/storage.py", "added": 12, "removed": 3}, {"path": "app/forms/login.py", "added": 40, "removed": 0}, {"path": "tests/test_login.py", "added": 18, "removed": 2},], on_keep=on_keep, on_reject=on_reject), width=520)When to use
Section titled “When to use”- Under an agent’s chat, once it has edited files, so the user reviews them before keeping them.
import pyzed as pzfrom pyzed import ui
class Review(pz.App): def __init__(self): self.files = [{"path": "app/storage.py", "added": 12, "removed": 3}]
def keep(self, path=None): # None: every file self.files = [f for f in self.files if path is not None and f["path"] != path]
def view(self): return ui.EditsBar(files=self.files, on_keep=lambda e: self.keep(), on_keep_file=lambda e: self.keep(e.value), on_open=lambda e: self.open(e.value))Variants
Section titled “Variants”Unfolded ones are drawn as they look after a click on the header.


Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 12, "removed": 3}, {"path": "ui/form.py", "added": 40, "removed": 0}]), width=440)

Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 12, "removed": 3}, {"path": "ui/form.py", "added": 40, "removed": 0}]), width=440)

Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 2, "removed": 2}]), width=440)

Code
pz.container(ui.EditsBar(files=[{"path": "app.py"}, {"path": "README.md"}]), width=440)Events
Section titled “Events”Edits bar has 5 events of its own, listed below. 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.
It is a pz.Component, so it also raises on_mount and on_unmount, and its handlers get a pz.Event whose value holds the data.
| Event | Handler gets | When |
|---|---|---|
on_keep |
(event) |
Keep all. |
on_reject |
(event) |
Reject all. |
on_keep_file |
(event) |
Keep on a file (event.value is its path). |
on_reject_file |
(event) |
Reject on a file. |
on_open |
(event) |
A file was clicked. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Review(pz.App): def __init__(self): self.files = [{"path": "app/storage.py", "added": 12, "removed": 3}, {"path": "tests/test_storage.py", "added": 8, "removed": 0}]
def drop(self, path=None): # None: every file self.files = [f for f in self.files if path is not None and f["path"] != path]
def view(self): # event.value is the file's path return ui.EditsBar(files=self.files, on_keep=lambda e: self.drop(), on_reject=lambda e: self.drop(), on_keep_file=lambda e: self.drop(e.value), on_reject_file=lambda e: self.drop(e.value), on_open=lambda e: print("open", e.value))from dataclasses import dataclass
@dataclassclass Done: path: str = ""
class Review(pz.App): files = [{"path": "app/storage.py", "added": 12, "removed": 3}]
def update(self, message): match message: case Done(""): self.files = [] case Done(path): self.files = [f for f in self.files if f["path"] != path]
def view(self): return ui.EditsBar(files=self.files, on_keep=Done(), on_keep_file=lambda e: Done(e.value))from dataclasses import dataclass
@dataclass(frozen=True)class State: files: tuple = ({"path": "app/storage.py", "added": 12, "removed": 3},)
def view(state, set_state): without = lambda path: tuple(f for f in state.files if f["path"] != path) return ui.EditsBar(files=list(state.files), on_keep=lambda e: set_state(files=()), on_keep_file=lambda e: set_state(files=without(e.value)))Properties and API
Section titled “Properties and API”ui.EditsBar
Section titled “ui.EditsBar”class EditsBarA component listing the files an agent changed, like Zed’s edits bar: 3 files changed with Reject all and Keep all, unfolding to one row per file with its diff stat, Reject and Keep.
| Property | Default | Description |
|---|---|---|
files |
None |
Dicts or objects with path and optional added and removed line counts. |
theme |
None |
Theme. |
Events: on_keep, on_reject, on_keep_file, on_reject_file, on_open (events).