Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ diffui/
│ ├── filelist.py # FileList: tree or risk-ordered files
│ └── screens.py # Help, comment composer, agent prompt and commit picker
├── static/ # Preact frontend: app.js, components/, lib/ (use*.js hooks, api.js, keys.js, markdown.js, utils.js), style.css
└── themes/ # Theme dataclass, 16 themes in definitions.py
└── themes/ # Theme dataclass, 17 themes in definitions.py
```

## Shared patterns
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ The header shows the current scope. The browser has the same choices in its view

## Display

- 16 color themes, with Graphite as the default: Graphite, Catppuccin Mocha, Catppuccin Latte, GitHub Dark, Dracula, One Dark, Solarized Dark, Gruvbox Dark, Nord, Tokyo Night, Rosé Pine, Rosé Pine Moon, Monokai Pro, Kanagawa, Everforest and Ayu Dark.
- 17 color themes, with Graphite as the default: Graphite, Graphite High Contrast, Catppuccin Mocha, Catppuccin Latte, GitHub Dark, Dracula, One Dark, Solarized Dark, Gruvbox Dark, Nord, Tokyo Night, Rosé Pine, Rosé Pine Moon, Monokai Pro, Kanagawa, Everforest and Ayu Dark.
- The blame gutter shows the author and age of each line.
- `.md` files get a rendered preview and images show inline. Markdown is sanitized before rendering, and diagram blocks go to kroki.io.
- Font size and line wrap are in Settings and the command palette.
Expand Down
56 changes: 56 additions & 0 deletions diffui/themes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,61 @@
},
)

GRAPHITE_HIGH_CONTRAST = Theme(
name="Graphite High Contrast",
bg="#0b0c0f",
bg_dark="#07080a",
fg="#e6e9ef",
fg_muted="#9aa3b2",
border="#323843",
accent="#7fb2f0",
add_bg="#1d4a2c",
add_hover="#24583a",
remove_bg="#57212a",
remove_hover="#682832",
hunk_bg="#172033",
hunk_fg="#a9c4ea",
gutter_fg="#8a93a3",
gutter_sep="#323843",
hover_bg="#1a1d23",
comment_bg="#14171c",
comment_header_bg="#1c2027",
comment_accent="#7fb2f0",
delete_fg="#ff9c9c",
warn_bg="#3a3115",
warn_hover="#4a3e1a",
warn_fg="#f0c862",
highlight_bg="rgba(255, 214, 102, 0.38)",
highlight_border="rgba(255, 214, 102, 0.7)",
syntax={
Token.Keyword: "#c9b1f5",
Token.Keyword.Constant: "#f0b07a",
Token.Keyword.Declaration: "#c9b1f5",
Token.Keyword.Namespace: "#c9b1f5",
Token.Keyword.Type: "#f0c862",
Token.Name.Builtin: "#8cc4ff",
Token.Name.Function: "#8cc4ff",
Token.Name.Class: "#f0c862",
Token.Name.Decorator: "#f0b07a",
Token.Name.Exception: "#ff9c9c",
Token.Name.Variable: "#e6e9ef",
Token.Name.Attribute: "#8cc4ff",
Token.Name.Tag: "#ff9c9c",
Token.Literal.String: "#a9e09a",
Token.Literal.String.Doc: "#9fd08f",
Token.Literal.String.Interpol: "#f0b07a",
Token.Literal.String.Escape: "#f0b07a",
Token.Literal.Number: "#f0b07a",
Token.Operator: "#9ee0e0",
Token.Operator.Word: "#c9b1f5",
Token.Punctuation: "#b7bdc9",
Token.Comment: "#b3bac7",
Token.Comment.Single: "#b3bac7",
Token.Comment.Multiline: "#b3bac7",
Token.Name.Builtin.Pseudo: "#ff9c9c",
},
)

CATPPUCCIN_MOCHA = Theme(
name="Catppuccin Mocha",
bg="#1e1e2e",
Expand Down Expand Up @@ -855,6 +910,7 @@

ALL_THEMES = [
GRAPHITE,
GRAPHITE_HIGH_CONTRAST,
CATPPUCCIN_MOCHA,
GITHUB_DARK,
DRACULA,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "diffui"
version = "0.11.3"
version = "0.12.0"
description = "UI for reviewing AI agent diffs"
requires-python = ">=3.10"
dependencies = [
Expand Down
30 changes: 30 additions & 0 deletions tests/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ def test_no_saved_theme_uses_default_and_saved_theme_wins(self, monkeypatch):
assert state.AppState().theme is DEFAULT_THEME
monkeypatch.setattr(state, "load_settings", lambda: {"theme": "Dracula"})
assert state.AppState().theme.name == "Dracula"


def _luminance(hex_color: str) -> float:
channels = [int(hex_color[i : i + 2], 16) / 255 for i in (1, 3, 5)]
linear = [c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4 for c in channels]
return 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2]


def _contrast(a: str, b: str) -> float:
high, low = sorted((_luminance(a), _luminance(b)), reverse=True)
return (high + 0.05) / (low + 0.05)


class TestGraphiteHighContrast:
def test_code_colors_stay_readable_on_every_line_background(self):
from diffui.themes.definitions import GRAPHITE_HIGH_CONTRAST as theme

for background in (theme.bg, theme.add_bg, theme.remove_bg):
for color in (theme.fg, *theme.syntax.values()):
assert _contrast(color, background) >= 4.5, f"{color} on {background}"

def test_changed_lines_stand_out_more_than_in_graphite(self):
from diffui.themes.definitions import GRAPHITE
from diffui.themes.definitions import GRAPHITE_HIGH_CONTRAST as theme

for field_name in ("add_bg", "remove_bg"):
assert _contrast(getattr(theme, field_name), theme.bg) >= 1.5
assert _contrast(getattr(theme, field_name), theme.bg) > _contrast(
getattr(GRAPHITE, field_name), GRAPHITE.bg
)
Loading