[PATCH RFC 09/11] review-tui: extract the Msgs column renderer from TrackedSeriesItem
Christian Brauner <[email protected]> Sat, 18 Jul 2026 00:37:45 +0200
| Newsgroups | org.kernel.linux.tools |
|---|---|
| Message-ID | <[email protected]> |
The tracker list computes the Msgs column (thread total plus an unseen badge) inline in TrackedSeriesItem.compose(). Per-version child rows need the exact same column, so pull the computation out into _msgs_fields() and the styled append into _append_msgs(). No functional change. Assisted-by: LLM Signed-off-by: Christian Brauner (Amutable) <[email protected]> --- src/b4/review_tui/_tracking_app.py | 95 ++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/src/b4/review_tui/_tracking_app.py b/src/b4/review_tui/_tracking_app.py index cc20ad6..8800383 100644 --- a/src/b4/review_tui/_tracking_app.py +++ b/src/b4/review_tui/_tracking_app.py @@ -516,6 +516,54 @@ def _format_attestation(att: str, app: Any = None) -> Optional[RichText]: return text +def _msgs_fields( + message_count: Optional[int], seen_message_count: Optional[int] +) -> Tuple[str, str, bool]: + """Render the Msgs column for a (total, seen) message count pair. + + Returns (base, badge, base_accent): "1" (all seen), "6" accented (all + new), "6" + "(3)" (mixed). A never-fetched thread has no count and + renders as "-". The badge is accented whenever it is non-empty. + """ + if message_count is None: + return '-', '', False + if message_count == 0: + return '0', '', False + delta = ( + message_count - seen_message_count + if (seen_message_count is not None and message_count > seen_message_count) + else 0 + ) + if delta == message_count: + # All follow-ups are new + return str(message_count), '', True + if delta > 0: + # Mixed: total + (unseen) + return str(message_count), f'({delta})', False + # All seen + return str(message_count), '', False + + +def _append_msgs( + label: RichText, + app: Any, + message_count: Optional[int], + seen_message_count: Optional[int], +) -> None: + """Append the Msgs column (total + unseen badge) to *label*.""" + base, badge, base_accent = _msgs_fields(message_count, seen_message_count) + base_style = '' + badge_style = '' + if base_accent or badge: + accent = f'bold {resolve_styles(app)["warning"]}' + if base_accent: + base_style = accent + if badge: + badge_style = accent + label.append(f' {base.rjust(3)}', style=base_style) + label.append(f'{badge:<3s}', style=badge_style) + + class TrackedSeriesItem(ListItem): """A single tracked series entry in the listing.""" @@ -553,36 +601,6 @@ class TrackedSeriesItem(ListItem): art_str = f'{a}·{r}·{t}' else: art_str = '-' - fc = self.series.get('message_count') - sc = self.series.get('seen_message_count') - if fc is not None: - delta = (fc - sc) if (sc is not None and fc > sc) else 0 - else: - delta = 0 - # Msgs display: "1" (all seen), "6" accent (all new), "6(3)" mixed - if fc is None: - fu_base = '-' - fu_badge = '' - base_accent = False - elif fc == 0: - fu_base = '0' - fu_badge = '' - base_accent = False - elif delta == fc: - # All follow-ups are new - fu_base = str(fc) - fu_badge = '' - base_accent = True - elif delta > 0: - # Mixed: total + (unseen) - fu_base = str(fc) - fu_badge = f'({delta})' - base_accent = False - else: - # All seen - fu_base = str(fc) - fu_badge = '' - base_accent = False # Build compact prefix using LoreSubject to extract subsystem/modifier tokens ls = b4.LoreSubject(subject) extras = ls.get_extra_prefixes(exclude=['patch']) @@ -605,17 +623,12 @@ class TrackedSeriesItem(ListItem): label.append(' ') label.append(' ') label.append(art_str.rjust(7)) - base_style = '' - badge_style = '' - if base_accent or fu_badge: - ts = resolve_styles(self.app) - accent = f'bold {ts["warning"]}' - if base_accent: - base_style = accent - if fu_badge: - badge_style = accent - label.append(f' {fu_base.rjust(3)}', style=base_style) - label.append(f'{fu_badge:<3s}', style=badge_style) + _append_msgs( + label, + self.app, + self.series.get('message_count'), + self.series.get('seen_message_count'), + ) label.append(f' {symbol}{flag} {subject_display}') yield Label(label, markup=False) -- 2.53.0