Skip to content

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 →

Edits barEdits bar
  • Under an agent’s chat, once it has edited files, so the user reviews them before keeping them.
import pyzed as pz
from 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))

Unfolded ones are drawn as they look after a click on the header.

Edits bar: FoldedEdits bar: Folded
Folded
Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 12, "removed": 3},
{"path": "ui/form.py", "added": 40, "removed": 0}]),
width=440)
Edits bar: UnfoldedEdits bar: Unfolded
Unfolded
Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 12, "removed": 3},
{"path": "ui/form.py", "added": 40, "removed": 0}]),
width=440)
Edits bar: One fileEdits bar: One file
One file
Code
pz.container(ui.EditsBar(files=[{"path": "app.py", "added": 2, "removed": 2}]), width=440)
Edits bar: Without line countsEdits bar: Without line counts
Without line counts
Code
pz.container(ui.EditsBar(files=[{"path": "app.py"}, {"path": "README.md"}]), width=440)

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().

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))
class EditsBar

A 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).

Full reference →