Skip to content

API turboframe.ui.diffview

rafageist edited this page Dec 4, 2026 · 4 revisions

turboframe.ui.diffview

Source: turboframe/ui/diffview.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.

A diff as a code review shows it: unified, or side by side.

DiffView reads git's diff (turboframe.git.parse_diff) and draws it itself: each file under a bar with its path and +N −M; each hunk under a row with where it starts and the function it is in; each line after its old and new numbers, with the whole row on red (removed), green (added) or the editor's colour (unchanged), and inside a changed line the words that changed in a stronger shade. Side by side, the old file is at the left and the new one at the right, a removed line next to the added line that replaced it.

A bar goes over the rows (Up, Down, PgUp, PgDn, Home, End; Left and Right scroll sideways): Enter asks to open the file at that line (LineChosen), N and P go to the next and the previous hunk, S changes between unified and side by side (remembered in the application's store).

An application sets, once, DiffView.store (load() -> dict and save(dict): its config) and DiffView.syntax: a function (path, text) giving its editor's colours of text as a file at path, per line (start, end, token kind); highlight_spans(editor, text) reads them from a Textual TextArea that has highlighted it. Without them the choice holds for the session and the code has no syntax colours.

Contents

SETTING, DiffView, Row, highlight_spans

SETTING

'git_diff_side_by_side'

class DiffView

class DiffView(ScrollView, TVViewMixin)
DiffView()

A diff, unified or side by side, with a bar over its rows.

  • show(text: str, conflict: bool = False, path: str = '') -> None: A diff (git's text); with conflict, a file in conflict (git's markers, our side, theirs), path the file (for its colours).
  • show_message(text: str) -> None: Plain text where the diff goes (what an area holds, why there is nothing).
  • rows_text() -> list[str]: The rows as they read (for tests and copying): unified or side by side.
  • action_move(by: int) -> None
  • action_page(by: int) -> None
  • action_edge(end: int) -> None
  • action_sideways(by: int) -> None
  • action_jump(direction: int) -> None: To the next (or previous) hunk's first line.
  • action_toggle() -> None
  • action_choose() -> None

class Row

class Row
Row(kind: str, text: str = '', style: str = '', file: git.DiffFile | None = None, hunk: git.Hunk | None = None, left: git.DiffLine | None = None, right: git.DiffLine | None = None, left_spans: tuple = (), right_spans: tuple = (), left_syntax: tuple = (), right_syntax: tuple = ())

What a row of the view shows.

highlight_spans

def highlight_spans(editor, text: str) -> list[list[tuple[int, int, str]]]

The colours a Textual TextArea (with a language) gives text: per line, (start, end, token kind) by character. A hidden editor colours it, so every language comes out as it does in the editor.

Clone this wiki locally