Skip to content

Diff

Native virtualized viewer for unified patches and source files.

Native Diff preview

A real Linux/X11 native capture in light appearance. The same control also supports the initial dark theme.

Runnable example

import gpyui as ui

patch = "--- a/settings.py\n+++ b/settings.py\n@@ -1,2 +1,2 @@\n-timeout = 30\n+timeout = 60\n retries = 3\n"
control = ui.Diff(patch, mode="split", context_lines=3).style(height=230, full_width=True)
toggle = ui.Button(
    "Switch view",
    on_click=lambda: setattr(control, "mode", "unified" if control.mode == "split" else "split"),
)

app = ui.Application(ui.Column([control, toggle]), title="Diff", width=640, height=435)
app.run()

Run this in a fresh Python process on a desktop with the native build installed.

Properties

Property Default Type / accepted values Update
patch "" str; up to 2 MB UTF-8 Assignment
mode "unified" unified · split Assignment
source null source str or None Constructor only
path "source.txt" str Constructor only
context_lines null nonnegative int or None Assignment
split_ratio 0.5 number between 0.1 and 0.9 Assignment
line_numbers true bool Assignment
header_visible true bool Assignment
soft_wrap false bool Assignment

All controls support visible and dispose(). Hiding or detaching retains native state; disposal permanently releases it. See Control.

Events and state

  • on_selection(event): Receives the Diff selection range or None when selection clears.
  • on_file_expand(event): Receives the path of the expanded file.
  • on_file_collapse(event): Receives the path of the collapsed file.

Handlers can take zero arguments or one Event, and can be synchronous or async. They run on the owned Python asyncio loop. See events and asyncio.

Contract and limits

Assign patch to replace a unified or Git patch. Pass source= and path= for an unchanged file. on_selection receives a range dictionary or None with one-based lines and old/new sides. on_file_expand and on_file_collapse receive a file path. Text payloads are limited to 2 MB.

All controls accept pixel layout and semantic theme styling through .style(...). Collections are copied on assignment/read: reassign them to submit updates.

Python implementation · Native builders · Full coverage and remaining Kit APIs