fix(output): respect terminal width and truncate long project paths

Replace hardcoded FALLBACK_WIDTH=200 with ContentArrangement::Dynamic
so comfy-table auto-fits to the actual terminal. Truncate project paths
to the last ~40 chars with an ellipsis prefix in sessions list.

Closes claudbg-6dgc

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
Elijah Voigt 2 months ago
parent f3258ee2b5
commit d9ceb916ba

@ -1,11 +1,11 @@
--- ---
# claudbg-6dgc # claudbg-6dgc
title: Table overflows terminal — truncate long columns and respect terminal width title: Table overflows terminal — truncate long columns and respect terminal width
status: todo status: completed
type: bug type: bug
priority: normal priority: normal
created_at: 2026-03-30T04:36:31Z created_at: 2026-03-30T04:36:31Z
updated_at: 2026-03-30T04:41:14Z updated_at: 2026-03-30T05:06:58Z
parent: claudbg-tci9 parent: claudbg-tci9
--- ---
@ -28,3 +28,8 @@ parent: claudbg-tci9
- `src/output/table.rs``render_table`, `FALLBACK_WIDTH` constant - `src/output/table.rs``render_table`, `FALLBACK_WIDTH` constant
- `src/commands/sessions.rs``list()` function that calls `render_table` - `src/commands/sessions.rs``list()` function that calls `render_table`
## Summary of Changes
- Removed hardcoded FALLBACK_WIDTH=200 from table.rs; table now uses ContentArrangement::Dynamic for automatic terminal width fitting
- In sessions list(), truncate project path to last ~40 chars with ellipsis prefix when longer

@ -189,10 +189,23 @@ pub async fn list(opts: &crate::cli::GlobalOpts) -> Result<()> {
crate::util::short_id(&session_id).to_string() crate::util::short_id(&session_id).to_string()
}; };
const MAX_PATH_LEN: usize = 40;
let display_path = if project_path.len() > MAX_PATH_LEN {
let boundary = project_path
.char_indices()
.rev()
.map(|(i, _)| i)
.nth(MAX_PATH_LEN - 1)
.unwrap_or(0);
format!("…{}", &project_path[boundary..])
} else {
project_path
};
rows.push(vec![ rows.push(vec![
display_id, display_id,
last_msg_at, last_msg_at,
project_path, display_path,
model, model,
message_count.to_string(), message_count.to_string(),
]); ]);

@ -12,12 +12,6 @@ use crate::error::Result;
pub fn render_table(headers: &[&str], rows: &[Vec<String>]) -> Result<String> { pub fn render_table(headers: &[&str], rows: &[Vec<String>]) -> Result<String> {
let mut table = Table::new(); let mut table = Table::new();
table.set_content_arrangement(ContentArrangement::Dynamic); table.set_content_arrangement(ContentArrangement::Dynamic);
// Ensure a sensible minimum width so content is never truncated in non-interactive
// environments (CI, Nix sandbox, pipes) where the terminal may report a very narrow
// width or no width at all.
const FALLBACK_WIDTH: u16 = 200;
let width = table.width().unwrap_or(FALLBACK_WIDTH).max(FALLBACK_WIDTH);
table.set_width(width);
table.set_header(headers); table.set_header(headers);
for row in rows { for row in rows {
table.add_row(row); table.add_row(row);

Loading…
Cancel
Save