diff --git a/src/gui/_home.py b/src/gui/_home.py index 5f7e12d..0cca6b2 100644 --- a/src/gui/_home.py +++ b/src/gui/_home.py @@ -36,6 +36,24 @@ class _StashedUpload: return self._data +def _format_size(n: int) -> str: + """Human-readable byte count for file sizes shown in the GUI. + + Bytes are never displayed — the smallest unit is KB, even for sub- + kilobyte files (e.g. ``0.5 KB`` for 512 bytes). Steps up to MB + once the count reaches 1 MiB, then to GB at 1 GiB. Always one + decimal place. + """ + KB = 1024 + MB = 1024 * 1024 + GB = 1024 * 1024 * 1024 + if n < MB: + return f"{n / KB:.1f} KB" + if n < GB: + return f"{n / MB:.1f} MB" + return f"{n / GB:.1f} GB" + + def _render_stats_overview(findings_by_file: dict) -> None: """4-card grid above the per-file findings — summarizes the run. @@ -224,13 +242,10 @@ def _home_page() -> None: n_files = len(home_uploads) if n_files: total_bytes = sum(meta["size"] for meta in home_uploads.values()) - if total_bytes >= 1024: - total_label = f"{total_bytes / 1024:.1f} KB" - else: - total_label = f"{total_bytes:,} B" files_word = "file" if n_files == 1 else "files" meta_html = ( - f'{n_files} {files_word} · {_html.escape(total_label)} total' + f'{n_files} {files_word} · ' + f'{_html.escape(_format_size(total_bytes))} total' ) else: meta_html = "No files imported yet" @@ -275,7 +290,7 @@ def _home_page() -> None: col_size.markdown( f'