Skip to content

refactor(terminal): split terminal helpers into modules - #1127

Merged
ryoppippi merged 1 commit into
mainfrom
codex/split-terminal-crate
May 23, 2026
Merged

refactor(terminal): split terminal helpers into modules#1127
ryoppippi merged 1 commit into
mainfrom
codex/split-terminal-crate

Conversation

@ryoppippi

@ryoppippi ryoppippi commented May 23, 2026

Copy link
Copy Markdown
Member

Splits the ccusage-terminal Rust crate out of its single lib.rs file into focused private modules for table rendering, styling, terminal width detection, title rendering, and display width helpers.

The public exports remain unchanged from lib.rs, and the terminal snapshots keep the same rendered output with only their module paths updated.

@coderabbitai please review this refactor, especially that the module split preserves the existing public API and snapshot output.

Testing:

  • direnv exec . cargo test --manifest-path rust/Cargo.toml -p ccusage-terminal
  • direnv exec . pnpm run format
  • direnv exec . pnpm typecheck
  • direnv exec . pnpm run test
  • direnv exec . git push -u origin codex/split-terminal-crate (pre-push: cargo test, typos, oxfmt, gitleaks, clippy)

Summary by cubic

Split the ccusage-terminal crate’s single lib.rs into focused internal modules with no public API or terminal output changes.

  • Refactors
    • Moved code into private modules: table, style, title, terminal, and width.
    • Kept the same public exports via lib.rs re-exports.
    • Updated tests and snapshot files to reference new module paths; snapshot content is unchanged.

Written for commit d8c775e. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • Refactor
    • Reorganized terminal UI library into modular components for improved code maintainability and structure. Public API remains unchanged.

Review Change Stack

Break the ccusage-terminal crate out of the single lib.rs file while keeping the public exports unchanged.

Move table rendering, terminal styling, title rendering, width handling, and terminal width discovery into focused private modules so future terminal work has clearer ownership.

The snapshot outputs are unchanged; their files move only because the tests now live beside the extracted modules.
@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR refactors the ccusage-terminal crate from a monolithic single-file implementation into a modular, organized structure. All functionality is decomposed into five focused modules (styling, table rendering, terminal detection, title rendering, and width utilities) while lib.rs becomes a clean re-export layer that preserves the public API surface without code duplication.

Changes

Terminal Module Organization

Layer / File(s) Summary
ANSI-aware width utilities
rust/crates/ccusage-terminal/src/width.rs
New module adds visible_width, contains_ansi, char_display_width, and line-oriented helpers (visible_width_max_line, visible_width_sum) to compute visible character width while correctly ignoring ANSI escape sequences.
Terminal styling with Color and TerminalStyle
rust/crates/ccusage-terminal/src/style.rs
New module introduces Color enum and TerminalStyle struct. The color() function conditionally applies ANSI codes based on style flags (color, no_color), NO_COLOR/FORCE_COLOR environment variables, and terminal detection. Unit test verifies no_color prevents formatting.
Terminal width detection via ioctl and COLUMNS
rust/crates/ccusage-terminal/src/terminal.rs
New module exports terminal_width() that reads COLUMNS environment variable, falls back to Unix ioctl on TTY to query stdout terminal size, and defaults to a fixed width. Platform-specific implementation handles ioctl constants and unsafe FFI on Unix while stubbing non-Unix.
Boxed title rendering
rust/crates/ccusage-terminal/src/title.rs
New module implements print_box_title() to render multi-line text centered within a Unicode box using visible width calculations and blue coloring. Includes property test (single box, one top/bottom border) and snapshot test.
Terminal table rendering with responsive columns
rust/crates/ccusage-terminal/src/table.rs
New module provides SimpleTable with Align enum and comprehensive rendering pipeline: constructor/builder methods, column width computation from headers/cells, responsive fitting within terminal width, multiline cell expansion, ANSI-aware truncation with ellipsis, ISO date (YYYY-MM-DD) compaction to two-line format, and box-drawing rendering. Tests cover date compaction, width fitting, truncation edge cases (ANSI preservation), and two full snapshot renders (multiline and narrow/wrapped/compacted).
Module organization and public API
rust/crates/ccusage-terminal/src/lib.rs
lib.rs reduced from all-in-one implementation (726 lines removed) to a thin entry point with module declarations and pub use re-exports of Color, TerminalStyle, Align, SimpleTable, terminal_width, print_box_title, and color from their respective modules.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

The PR involves substantial refactoring of a monolithic module into five focused modules with significant implementation density. Review requires understanding the data shapes (Color, TerminalStyle, Align, SimpleTable), the width calculation logic (ANSI-aware visible width, char display width rules), conditional styling based on environment variables, terminal detection via ioctl and TTY checks, table rendering pipeline with column sizing and fitting heuristics, ANSI-aware truncation edge cases, and the public API re-export structure. The variety and interdependencies across modules demand reasoning for each layer, though homogeneous patterns within table rendering (wrapping, padding, truncation) provide some repetition.

Suggested reviewers

  • ubugeeei

Poem

🐰 One monolith became five, each module now alive,
Width calculations dance with ANSI sequences true,
Styled tables fit the terminal, truncate with flair,
Boxed titles centered neatly, width-aware everywhere—
From chaos, order emerges in your refactored lair! 📦✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: refactoring the terminal crate by splitting it from a monolithic lib.rs into organized modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/split-terminal-crate

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.

@ryoppippi

Copy link
Copy Markdown
Member Author

@coderabbitai please review this PR. The terminal crate has been split into focused modules while keeping the public API and snapshot-rendered output unchanged.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide d8c775e Commit Preview URL

Branch Preview URL
May 23 2026, 01:36 PM

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get PR details and file list
gh pr view 1127 --repo ryoppippi/ccusage --json title,body,files,additions,deletions | jq '.'

# Get the diff for the PR
gh pr diff 1127 --repo ryoppippi/ccusage

Length of output: 53546


@ryoppippi: The module split looks clean and correct. Here's a summary of what I verified:

Public API — fully preserved

All 7 public symbols (Align, Color, TerminalStyle, SimpleTable, terminal_width, print_box_title, color) are re-exported unchanged from lib.rs.

Module dependency graph — acyclic

graph TD
    lib["lib.rs (re-exports)"]
    table["table.rs"]
    style["style.rs"]
    terminal["terminal.rs"]
    title["title.rs"]
    width["width.rs"]

    lib --> table
    lib --> style
    lib --> terminal
    lib --> title
    table --> style
    table --> terminal
    table --> width
    title --> style
    title --> width
Loading

No circular dependencies; leaf modules (width, style, terminal) have zero internal imports.

Visibility modifiers — correct

  • DEFAULT_TERMINAL_WIDTH promoted to pub(crate) in terminal.rs so table.rs can reference it.
  • visible_width, contains_ansi, char_display_width, visible_width_max_line, visible_width_sum all pub(crate) in width.rs.
  • use_color stays private in style.rs.
  • render_lines and box_title_lines remain private; their mod tests child modules can access them via Rust's privacy rules.

Snapshot files — correctly renamed

All 4 snapshot files renamed to match new module paths (ccusage_terminal__table__tests__*, ccusage_terminal__title__tests__*); rendered content is byte-for-byte identical, only the source: path and new assertion_line: metadata field changed.

Tests redistributed to their respective modules

Everything looks good. Approving.

[approve]

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rust/crates/ccusage-terminal/src/table.rs`:
- Around line 142-149: The compact-dates path sets first_column_min to 12 which
prevents the later narrowing to <=10; change the minimum passed to
fit_widths_to_terminal when self.compact_dates is true from 12 to 10 (i.e. let
first_column_min = if self.compact_dates { 10 } else { 10 } or simply use 10 for
the compact case), so that widths (the first column produced by
fit_widths_to_terminal) can be reduced to 10 and allow
compact_date_row()/with_date_compaction(true) to take effect; keep the existing
follow-up branch that applies widths.first_mut().max(10) if you want to enforce
the 10 floor.

In `@rust/crates/ccusage-terminal/src/width.rs`:
- Around line 30-35: Add the unicode-width crate to the crate dependencies and
replace the ad-hoc ASCII check in char_display_width with the unicode-width API:
import unicode_width::UnicodeWidthChar and return
UnicodeWidthChar::width_cjk(ch).map(|w| w as usize).unwrap_or(0) (or use
.unwrap_or(0) on UnicodeWidthChar::width if you prefer non-CJK semantics) so
combining marks return 0 and proper CJK/ambiguous widths return 2; update any
uses of char_display_width/visible_width to rely on this corrected width
calculation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c715bac3-eb14-401e-9f4c-66a31686e28c

📥 Commits

Reviewing files that changed from the base of the PR and between d4b5c3c and d8c775e.

⛔ Files ignored due to path filters (4)
  • rust/crates/ccusage-terminal/src/snapshots/ccusage_terminal__table__tests__snapshots_ansi_truncation_boundary.snap is excluded by !**/*.snap
  • rust/crates/ccusage-terminal/src/snapshots/ccusage_terminal__table__tests__snapshots_full_table_with_multiline_cells_and_separators.snap is excluded by !**/*.snap
  • rust/crates/ccusage-terminal/src/snapshots/ccusage_terminal__table__tests__snapshots_narrow_table_with_wrapping_truncation_and_compact_dates.snap is excluded by !**/*.snap
  • rust/crates/ccusage-terminal/src/snapshots/ccusage_terminal__title__tests__snapshots_multiline_box_title_layout.snap is excluded by !**/*.snap
📒 Files selected for processing (6)
  • rust/crates/ccusage-terminal/src/lib.rs
  • rust/crates/ccusage-terminal/src/style.rs
  • rust/crates/ccusage-terminal/src/table.rs
  • rust/crates/ccusage-terminal/src/terminal.rs
  • rust/crates/ccusage-terminal/src/title.rs
  • rust/crates/ccusage-terminal/src/width.rs

Comment thread rust/crates/ccusage-terminal/src/table.rs
Comment thread rust/crates/ccusage-terminal/src/width.rs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="rust/crates/ccusage-terminal/src/table.rs">

<violation number="1" location="rust/crates/ccusage-terminal/src/table.rs:147">
P2: `compact_dates` fallback uses `max(10)`, which does not reduce the first column width, so date compaction may never activate in narrow tables.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

fit_widths_to_terminal(widths, &self.aligns, self.terminal_width, first_column_min);
if self.compact_dates && total_required > self.terminal_width {
if let Some(width) = widths.first_mut() {
*width = (*width).max(10);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: compact_dates fallback uses max(10), which does not reduce the first column width, so date compaction may never activate in narrow tables.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At rust/crates/ccusage-terminal/src/table.rs, line 147:

<comment>`compact_dates` fallback uses `max(10)`, which does not reduce the first column width, so date compaction may never activate in narrow tables.</comment>

<file context>
@@ -0,0 +1,508 @@
+            fit_widths_to_terminal(widths, &self.aligns, self.terminal_width, first_column_min);
+        if self.compact_dates && total_required > self.terminal_width {
+            if let Some(width) = widths.first_mut() {
+                *width = (*width).max(10);
+            }
+        }
</file context>

@pkg-pr-new

pkg-pr-new Bot commented May 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

ccusage

npx https://pkg.pr.new/ryoppippi/ccusage@1127

@ccusage/ccusage-darwin-arm64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-darwin-arm64@1127

@ccusage/ccusage-darwin-x64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-darwin-x64@1127

@ccusage/ccusage-linux-arm64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-linux-arm64@1127

@ccusage/ccusage-linux-x64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-linux-x64@1127

@ccusage/ccusage-win32-arm64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-win32-arm64@1127

@ccusage/ccusage-win32-x64

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/ccusage-win32-x64@1127

commit: d8c775e

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: d8c775e2cec8
Base SHA: d4b5c3c32021

This compares the Rust PR release binary against the configured base package on the same CI runner.

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new d4b5c3c32021 739.6ms 341.8ms 33.6ms 3
PR pkg.pr.new d8c775e2cec8 682.7ms 334.9ms 34.7ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: d4b5c3c32021; PR package: d8c775e2cec8. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 500.5ms 510.4ms 0.98x 2.01 GiB/s 1.97 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 365.6ms 368.9ms 0.99x 2.75 GiB/s 2.73 GiB/s

Package runtime diagnostics

Compares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 486.7ms 2.07 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 464.0ms 2.17 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 359.2ms 2.80 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 330.3ms 3.05 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs rust/target/release/ccusage directly. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude daily --offline --json 0.00 MiB 31.3ms 4.7ms 6.67x 0.05 MiB/s 0.33 MiB/s
claude session --offline --json 0.00 MiB 31.4ms 4.7ms 6.70x 0.05 MiB/s 0.33 MiB/s
codex daily --offline --json 0.00 MiB 31.1ms 4.4ms 7.14x 0.03 MiB/s 0.20 MiB/s
codex session --offline --json 0.00 MiB 31.6ms 4.3ms 7.38x 0.03 MiB/s 0.20 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs rust/target/release/ccusage directly. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude --offline --json 1.01 GiB 489.1ms 454.2ms 1.08x 2.06 GiB/s 2.22 GiB/s
codex --offline --json 1.01 GiB 353.9ms 326.9ms 1.08x 2.84 GiB/s 3.08 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 14.25 KiB 14.25 KiB +0.00 KiB 1.00x
installed native package binary 3289.49 KiB 3289.49 KiB +0.00 KiB 1.00x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@ryoppippi

Copy link
Copy Markdown
Member Author

@coderabbitai I split the two behavior changes into follow-up PR #1129. Please re-check #1127 as a mechanical module split with unchanged rendered snapshots and public API.

@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

PR SHA: d8c775e2cec8
Base SHA: d4b5c3c32021

This compares the PR package against the configured base package on the same CI runner.

Package runner startup

Execution setup measures any pre-benchmark package materialization used by the execution benchmark. Bunx temp cache measures one bunx -p <url> ccusage --version run with an empty Bun install cache. Warm reuses that cache and reports the median of repeated runs.

Package SHA Execution setup Bunx temp cache Bunx warm median Warm samples
Base pkg.pr.new d4b5c3c32021 460.9ms 658.1ms 33.7ms 3
PR pkg.pr.new d8c775e2cec8 485.4ms 528.5ms 34.0ms 3

Cached bunx execution performance

Runs the same large fixture through bunx -p <pkg.pr.new URL> ccusage after the Bun install cache has already been populated by the startup measurement. This separates cached package-runner execution from first-fetch package materialization.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base package: d4b5c3c32021; PR package: d8c775e2cec8. Both run through bunx -p <pkg.pr.new URL> ccusage using the warmed Bun install cache from package runner startup, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
bunx -p <pkg> ccusage claude --offline --json 1.01 GiB 509.4ms 499.1ms 1.02x 1.98 GiB/s 2.02 GiB/s
bunx -p <pkg> ccusage codex --offline --json 1.01 GiB 359.4ms 357.6ms 1.00x 2.80 GiB/s 2.82 GiB/s

Package runtime diagnostics

Compares the PR package wrapper, the installed native optional dependency binary, and the workspace release binary on the same large fixture. This identifies whether slow package results come from JavaScript wrapper overhead, the published native binary build, or the Rust core itself.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
All rows run --offline --json, measured by hyperfine with 0 warmups and 1 runs. This isolates wrapper overhead from the installed native optional dependency and the workspace release binary built on the runner.

Command Runtime Input Median Throughput Samples
claude --offline --json Package wrapper 1.01 GiB 483.4ms 2.08 GiB/s 1
claude --offline --json Installed native binary 1.01 GiB 469.6ms 2.14 GiB/s 1
codex --offline --json Package wrapper 1.01 GiB 369.2ms 2.73 GiB/s 1
codex --offline --json Installed native binary 1.01 GiB 331.5ms 3.04 GiB/s 1

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude daily --offline --json 0.00 MiB 31.1ms 30.7ms 1.01x 0.05 MiB/s 0.05 MiB/s
claude session --offline --json 0.00 MiB 31.0ms 30.6ms 1.01x 0.05 MiB/s 0.05 MiB/s
codex daily --offline --json 0.00 MiB 30.4ms 30.7ms 0.99x 0.03 MiB/s 0.03 MiB/s
codex session --offline --json 0.00 MiB 30.6ms 30.6ms 1.00x 0.03 MiB/s 0.03 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Base runs the published ccusage package from pkg.pr.new, installed before measurement; PR runs the published ccusage package from pkg.pr.new, installed before measurement. Both run --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude --offline --json 1.01 GiB 497.2ms 496.5ms 1.00x 2.03 GiB/s 2.03 GiB/s
codex --offline --json 1.01 GiB 367.3ms 353.7ms 1.04x 2.74 GiB/s 2.85 GiB/s

Artifact size

Artifact Base PR Delta Ratio
packed ccusage-*.tgz 14.25 KiB 14.25 KiB +0.00 KiB 1.00x
installed native package binary 3289.49 KiB 3289.49 KiB +0.00 KiB 1.00x

Lower medians and smaller artifacts are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the latest diff for PR `#1127`
gh pr diff 1127 --repo ryoppippi/ccusage

# Also get the file list
gh pr view 1127 --repo ryoppippi/ccusage --json files | jq '.files[].path'

Length of output: 50841


@ryoppippi: Re-checked against the current diff — this is a clean, purely mechanical module split. Here's what I verified:

Public API — preserved ✅

All 7 symbols (Align, Color, TerminalStyle, SimpleTable, terminal_width, print_box_title, color) are re-exported from lib.rs exactly as before.

Logic — zero changes ✅

Every function body, struct field, match arm, and algorithm in style.rs, terminal.rs, title.rs, table.rs, and width.rs is byte-for-byte identical to the original lib.rs implementations.

Visibility promotions — structural only ✅

  • DEFAULT_TERMINAL_WIDTH: constpub(crate) const (required so table.rs can reference it)
  • visible_width / contains_ansi / char_display_width / visible_width_max_line / visible_width_sum: private → pub(crate) (required so table.rs and title.rs can call them)

Neither change affects runtime behavior.

Snapshot files — rendered content unchanged ✅

All 4 snapshots were renamed to match new module paths (table::tests / title::tests). Only the source: path and the new assertion_line: insta metadata field changed — the rendered output below the --- separator is identical.

No behavior changes in this PR. Approving.

[approve]

@ryoppippi
ryoppippi merged commit fe3f480 into main May 23, 2026
54 of 55 checks passed
@ryoppippi
ryoppippi deleted the codex/split-terminal-crate branch May 23, 2026 13:55
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.

1 participant