refactor: Move terminal width detection to common utility function

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-08 17:25:36 -03:00
parent 8b38c3e345
commit 44d039a7c2
2 changed files with 30 additions and 25 deletions

View File

@@ -57,31 +57,8 @@ pub fn mode_list(
let is_terminal = stdout().is_terminal();
debug!("Output is terminal: {}", is_terminal);
// Get terminal width once, default to 80 if not available
// Only use max_len when output is a terminal
let term_width = if is_terminal {
if let Ok(columns_env) = env::var("COLUMNS") {
debug!("COLUMNS environment variable: {:?}", columns_env);
columns_env.parse::<usize>().unwrap_or(80)
} else {
// Try to get terminal size using termsize
match termsize::get() {
Some(size) => {
let width = size.cols as usize;
debug!("Terminal size detected: {} columns", width);
width
}
None => {
debug!("Failed to get terminal size, defaulting to 80");
80
}
}
}
} else {
debug!("Not a terminal, max_len will be ignored");
0 // Use 0 to indicate no truncation
};
// Get terminal width using the common function
let term_width = crate::modes::common::get_terminal_width();
debug!("Terminal width: {}", term_width);
let mut table = Table::new();