From 689f3778658a68b757c4d59416224ea28ec98360 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 25 Aug 2025 22:19:20 -0300 Subject: [PATCH] refactor: move terminal width calculation outside the loop Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- src/modes/list.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/modes/list.rs b/src/modes/list.rs index 4c82a52..54aa8bb 100644 --- a/src/modes/list.rs +++ b/src/modes/list.rs @@ -60,6 +60,17 @@ pub fn mode_list( return show_list_structured(items_with_meta, data_path, settings, output_format); } + // Get terminal width once, default to 80 if not available + let columns_env = env::var("COLUMNS").ok(); + debug!("COLUMNS environment variable: {:?}", columns_env); + + let term_width = columns_env + .as_ref() + .and_then(|w| w.parse::().ok()) + .unwrap_or(80); + + debug!("Terminal width: {}", term_width); + let mut table = Table::new(); table.set_format(*prettytable::format::consts::FORMAT_CLEAN); @@ -86,16 +97,6 @@ pub fn mode_list( .unwrap_or_else(|_| panic!("Unknown column {:?}", column.name)); let mut meta_name: Option<&str> = None; - // Get terminal width, default to 80 if not available - let columns_env = env::var("COLUMNS").ok(); - debug!("COLUMNS environment variable: {:?}", columns_env); - - let term_width = columns_env - .as_ref() - .and_then(|w| w.parse::().ok()) - .unwrap_or(80); - - debug!("Terminal width: {}", term_width); // Parse max_len, handling both numbers and percentages let column_width = if let Some(max_len_str) = &column.max_len {