(
blocks: &[SessionBlock],
token_limit: Option<&str>,
max_tokens: u64,
shared: &SharedArgs,
)
| 297 | } |
| 298 | |
| 299 | pub(crate) fn print_blocks_table( |
| 300 | blocks: &[SessionBlock], |
| 301 | token_limit: Option<&str>, |
| 302 | max_tokens: u64, |
| 303 | shared: &SharedArgs, |
| 304 | ) -> Result<()> { |
| 305 | if blocks.is_empty() { |
| 306 | eprintln!("No Claude usage data found."); |
| 307 | return Ok(()); |
| 308 | } |
| 309 | let terminal_width = terminal_width(); |
| 310 | let is_tty = std::io::stdout().is_terminal(); |
| 311 | let compact = should_use_compact_layout( |
| 312 | shared, |
| 313 | is_tty, |
| 314 | terminal_width, |
| 315 | BLOCKS_COMPACT_WIDTH_THRESHOLD, |
| 316 | ); |
| 317 | let actual_limit = parse_token_limit(token_limit, max_tokens); |
| 318 | print_box_title("Claude Code Token Usage Report - Session Blocks", shared); |
| 319 | let mut headers = vec!["Block Start", "Duration/Status", "Models", "Tokens"]; |
| 320 | let mut aligns = vec![Align::Left, Align::Left, Align::Left, Align::Right]; |
| 321 | if actual_limit.is_some_and(|limit| limit > 0) { |
| 322 | headers.push("%"); |
| 323 | aligns.push(Align::Right); |
| 324 | } |
| 325 | headers.push("Cost"); |
| 326 | aligns.push(Align::Right); |
| 327 | if shared.no_cost { |
| 328 | headers.pop(); |
| 329 | aligns.pop(); |
| 330 | } |
| 331 | let mut table = SimpleTable::new(headers, aligns, crate::terminal_style(shared)) |
| 332 | .with_terminal_width(terminal_width); |
| 333 | for block in blocks { |
| 334 | if block.is_gap { |
| 335 | let mut row = vec![ |
| 336 | color(shared, format_block_time(block, compact), Color::Grey), |
| 337 | color(shared, "(inactive)", Color::Grey), |
| 338 | color(shared, "-", Color::Grey), |
| 339 | color(shared, "-", Color::Grey), |
| 340 | ]; |
| 341 | if actual_limit.is_some_and(|limit| limit > 0) { |
| 342 | row.push(color(shared, "-", Color::Grey)); |
| 343 | } |
| 344 | if !shared.no_cost { |
| 345 | row.push(color(shared, "-", Color::Grey)); |
| 346 | } |
| 347 | table.push(row); |
| 348 | continue; |
| 349 | } |
| 350 | let total = block.token_counts.total(); |
| 351 | let mut row = vec![ |
| 352 | format_block_time(block, compact), |
| 353 | if block.is_active { |
| 354 | color(shared, "ACTIVE", Color::Green) |
| 355 | } else { |
| 356 | String::new() |
no test coverage detected