feat: add support for percentage-based max_len values
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -9,6 +9,7 @@ use prettytable::{color, row, Attr, Cell, Row, Table};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use serde_yaml;
|
||||
use std::env;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct ListItem {
|
||||
@@ -84,7 +85,27 @@ pub fn mode_list(
|
||||
.unwrap_or_else(|_| panic!("Unknown column {:?}", column.name));
|
||||
|
||||
let mut meta_name: Option<&str> = None;
|
||||
let column_width = column.max_len.unwrap_or(0);
|
||||
// Get terminal width, default to 80 if not available
|
||||
let term_width = env::var("COLUMNS")
|
||||
.ok()
|
||||
.and_then(|w| w.parse::<usize>().ok())
|
||||
.unwrap_or(80);
|
||||
|
||||
// Parse max_len, handling both numbers and percentages
|
||||
let column_width = if let Some(max_len_str) = &column.max_len {
|
||||
if max_len_str.ends_with('%') {
|
||||
// Parse percentage
|
||||
let percent = max_len_str.trim_end_matches('%')
|
||||
.parse::<f64>()
|
||||
.unwrap_or(0.0);
|
||||
(term_width as f64 * percent / 100.0) as usize
|
||||
} else {
|
||||
// Parse absolute number
|
||||
max_len_str.parse::<usize>().unwrap_or(0)
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
if let ColumnType::Meta = column_type {
|
||||
let parts: Vec<&str> = column.name.split(':').collect();
|
||||
|
||||
Reference in New Issue
Block a user