Merge branch 'feat/error-details' of github.com:aclist/dztui into feat/error-details

This commit is contained in:
aclist 2026-08-19 15:37:09 +09:00
commit c037cf9c40
2 changed files with 52 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import logging
import re
import textwrap
from typing import TYPE_CHECKING
from importlib import resources
@ -31,20 +32,40 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
logger.critical(e)
changelog = missing_changelog
# TODO: should long text be wrapped?
# FIXME: wrap long text
self.controller = controller
self.box = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL, spacing=5, margin_top=10
)
self.add(self.box)
expand_all = Gtk.Button(
label="Expand all", halign=Gtk.Align.START, margin_start=20
)
expand_all.connect("clicked", self._on_expand_all_clicked)
self.box.add(expand_all)
self.expanded = False
self.expanders: list[Gtk.Expander] = []
self.connect("key-press-event", self._on_keypress)
self.connect("key-press-event", self._on_esc_keypress)
changes = self._parse(changelog)
self._generate_nodes(changes)
self.show_all()
def _on_expand_all_clicked(self, button: Gtk.Button) -> None:
self.expanded = not self.expanded
for expander in self.expanders:
# NOTE: simply setting set_expanded() does not trigger activate() signal,
# so margins are not applied
if expander.get_expanded() == self.expanded:
continue
expander.activate()
label = "Collapse all" if self.expanded else "Expand all"
button.set_label(label)
def grab_content_area(self) -> None:
self.grab_focus()
@ -65,9 +86,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
text = "\n".join(changes)
formatted = format_pango(text)
container = Gtk.Box(
valign=Gtk.Align.START, halign=Gtk.Align.START
)
container = Gtk.Box(valign=Gtk.Align.START, halign=Gtk.Align.START)
label = Gtk.Label()
label.set_markup(formatted)
container.add(label)
@ -81,6 +100,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
expander.add(container)
expander.connect("activate", self._on_expand, container)
self.box.add(expander)
self.expanders.append(expander)
def _on_expand(self, expander: Gtk.Box, container: Gtk.Box) -> None:
"""
@ -94,6 +114,7 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
container.set_margin_bottom(15)
def _parse(self, changelog: str) -> list[tuple[str, list[str]]]:
release = ""
releases: list[tuple[str, list[str]]] = []
release_notes: list[str] = []
@ -107,5 +128,5 @@ class Changelog(HelpMenuMixin, ScrollableMixin, Gtk.ScrolledWindow): # type: ig
release = ""
release = line
continue
release_notes.append(line.rstrip())
release_notes.append(textwrap.fill(line.rstrip(), width=120))
return releases

View File

@ -1,20 +1,33 @@
import re
import pytest
from importlib import resources
from dzgui.const.constants import APP_NAME_LOWER, CHANGELOG_PATH
from pathlib import Path
@pytest.fixture
def changelog():
path = resources.files(APP_NAME_LOWER).joinpath(CHANGELOG_PATH)
return path
def changelog(request) -> None:
root = request.config.rootpath
changelog = Path(root).joinpath("CHANGELOG.md").read_text()
return changelog
def test_headings(changelog):
with open(changelog, "r") as f:
lines = f.readlines()
for line in lines:
if line.startswith("#"):
pass
# TODO: use regex
pass
def count_hash(line: str) -> int:
cnt = 0
for c in line:
if c == "#":
cnt += 1
return cnt
def test_changelog_prefix(changelog) -> None:
r = r".*(\[.*\]).*"
lines = changelog.splitlines()
sort = sorted(lines)
match = [line for line in sort if line.startswith("#")]
for m in match:
if "Changelog" in m:
assert count_hash(m) == 1
elif re.match(r, m) is not None:
assert count_hash(m) == 2
else:
assert count_hash(m) == 3