Skip to content

fix: widen token columns and add overflow-safe formatting#124

Open
mike1858 wants to merge 1 commit intomainfrom
fix/token-column-widths
Open

fix: widen token columns and add overflow-safe formatting#124
mike1858 wants to merge 1 commit intomainfrom
fix/token-column-widths

Conversation

@mike1858
Copy link
Member

@mike1858 mike1858 commented Feb 28, 2026

Problem

The Input (width 8) and Output (width 9) token columns in the TUI were too narrow for large values. A number like 106529574 (9 digits) got its leading digit clipped in the 8-wide Input column, displaying as 06529574 — silently losing magnitude information.

The four token columns also had inconsistent widths (8, 9, 10, 11, 12 depending on column and view), making the issue worse for some columns than others.

Fix

Widen columns: Unify all token columns (Cached, Input, Output, Reasoning) to width 12 via a TOKEN_COL_WIDTH constant, in both daily and session views. Separator rows use the same constant.

Overflow-safe formatting: Add format_number_fit(value, options, max_width) which cascades through progressively compact representations when the formatted number exceeds the column width:

  1. User's preferred format (commas, plain, etc.)
  2. Human-readable with configured decimals (e.g. 48.1b)
  3. Human-readable with fewer decimals (e.g. 48b)
  4. Plain digits

This ensures significant digits are never silently clipped — the number gets abbreviated instead.

Testing

  • 10 new tests for format_number_fit covering overflow fallback, boundary conditions, comma/human/plain modes, u64 totals, and zero values
  • All 209 existing tests pass
  • clippy, fmt, doc all clean

Closes #123

Summary by CodeRabbit

  • Refactor

    • Improved formatting for token/count columns to enforce consistent column widths and alignment across daily and session statistics, including totals and separators.
  • Bug Fix

    • Prevents overflow in narrow columns by gracefully falling back to more compact number representations.
  • Tests

    • Added comprehensive tests covering width-constrained number formatting and edge cases.

@coderabbitai
Copy link

coderabbitai bot commented Feb 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95a8606 and 94b5792.

📒 Files selected for processing (5)
  • src/analyzers/codex_cli.rs
  • src/analyzers/copilot.rs
  • src/tui.rs
  • src/utils.rs
  • src/utils/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils/tests.rs

📝 Walkthrough

Walkthrough

Added a TOKEN_COL_WIDTH constant and a new width-aware formatter format_number_fit, then updated TUI rendering to use it for all token-related columns and totals; comprehensive tests added. Minor stylistic control-flow tweaks in two analyzer modules; no public API signature changes.

Changes

Cohort / File(s) Summary
Formatting utility
src/utils.rs, src/utils/tests.rs
Added pub fn format_number_fit(..., max_width) with cascading fallbacks to fit numbers into a column width; added extensive tests covering fits, fallbacks, narrow widths, and edge cases.
TUI rendering
src/tui.rs
Introduced TOKEN_COL_WIDTH = 12; replaced format_number calls with format_number_fit(..., TOKEN_COL_WIDTH) for Cached/Input/Output/Reasoning token columns and totals; updated column constraints and separators for the new width-aware formatting.
Analyzers (minor control-flow)
src/analyzers/codex_cli.rs, src/analyzers/copilot.rs
Refactored match/if logic to guarded patterns: codex_cli now emits assistant message only when token usage hasn't been reported; copilot match arm converted to an if-guard style. No behavioral/signature changes intended.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰✨ I hopped in to make columns fit just right,
Numbers tucked in, no wild overflow in sight,
Prefered, human, digits — fallbacks in a row,
Tokens snug and tidy, a neat little show. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: widening token columns and adding overflow-safe formatting via format_number_fit.
Linked Issues check ✅ Passed All requirements from issue #123 are met: token columns unified to width 12, overflow-safe formatting prevents silent clipping, and significant digits are preserved via abbreviation.
Out of Scope Changes check ✅ Passed All changes directly address token column width and overflow formatting. Minor refactorings in codex_cli.rs and copilot.rs are within scope as formatting/styling adjustments.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/token-column-widths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Input (8) and Output (9) columns were too narrow for large token counts.
A value like 106529574 (9 digits) got its leading digit clipped in the
8-wide Input column, displaying as 06529574.

- Unify all token columns (Cached, Input, Output, Reasoning) to width 12
  via TOKEN_COL_WIDTH constant, in both daily and session views
- Add format_number_fit() that cascades through progressively compact
  formats (user pref → human-readable → fewer decimals → plain digits)
  so significant digits are never silently clipped
- Separator rows now use the constant for consistency
- Fix clippy::collapsible_match in tui.rs, codex_cli.rs, copilot.rs
- 10 new tests for format_number_fit
@mike1858 mike1858 force-pushed the fix/token-column-widths branch from 95a8606 to 94b5792 Compare February 28, 2026 00:51
@mike1858
Copy link
Member Author

mike1858 commented Mar 2, 2026

@coderabbitai Review.

@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

@mike1858: I'll review the changes in this PR.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input/Output Tokens Fields Not Big Enough For Me

1 participant