refactor: Remove duplicated functionality by relying on comfy-table
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -52,14 +52,6 @@ pub fn mode_list(
|
||||
return show_list_structured(items_with_meta, data_path, settings, output_format);
|
||||
}
|
||||
|
||||
// Check if output is a terminal
|
||||
let is_terminal = stdout().is_terminal();
|
||||
debug!("Output is terminal: {}", is_terminal);
|
||||
|
||||
// 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();
|
||||
table
|
||||
.load_preset(NOTHING)
|
||||
@@ -91,45 +83,6 @@ pub fn mode_list(
|
||||
.unwrap_or_else(|_| panic!("Unknown column {:?}", column.name));
|
||||
|
||||
let mut meta_name: Option<&str> = None;
|
||||
|
||||
// Parse max_len, handling numbers, percentages, and negative values
|
||||
// Only apply max_len when output is a terminal
|
||||
let column_width = if is_terminal {
|
||||
if let Some(max_len_str) = &column.max_len {
|
||||
debug!("Processing max_len for column '{}': {}", column.name, max_len_str);
|
||||
// Check if it's a negative number
|
||||
if max_len_str.starts_with('-') {
|
||||
// Parse as negative number
|
||||
let abs_value = max_len_str[1..].parse::<usize>().unwrap_or(0);
|
||||
if abs_value > term_width {
|
||||
0
|
||||
} else {
|
||||
term_width - abs_value
|
||||
}
|
||||
} else if max_len_str.ends_with('%') {
|
||||
// Parse percentage
|
||||
let percent_str = max_len_str.trim_end_matches('%');
|
||||
let percent = percent_str.parse::<f64>().unwrap_or(0.0);
|
||||
debug!("Percentage: {}%", percent);
|
||||
let computed_width = (term_width as f64 * percent / 100.0) as usize;
|
||||
debug!("Computed width: {}", computed_width);
|
||||
computed_width
|
||||
} else {
|
||||
// Parse absolute number
|
||||
let absolute_width = max_len_str.parse::<usize>().unwrap_or(0);
|
||||
debug!("Absolute width: {}", absolute_width);
|
||||
absolute_width
|
||||
}
|
||||
} else {
|
||||
debug!("No max_len specified for column '{}'", column.name);
|
||||
0
|
||||
}
|
||||
} else {
|
||||
debug!("Output is not a terminal, ignoring max_len");
|
||||
0
|
||||
};
|
||||
|
||||
debug!("Final column width for '{}': {}", column.name, column_width);
|
||||
|
||||
if let ColumnType::Meta = column_type {
|
||||
let parts: Vec<&str> = column.name.split(':').collect();
|
||||
@@ -140,8 +93,7 @@ pub fn mode_list(
|
||||
|
||||
let cell = match column_type {
|
||||
ColumnType::Id => {
|
||||
let mut cell =
|
||||
Cell::new(&string_column(item.id.unwrap_or(0).to_string(), column_width));
|
||||
let mut cell = Cell::new(item.id.unwrap_or(0).to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
@@ -153,13 +105,12 @@ pub fn mode_list(
|
||||
cell
|
||||
}
|
||||
ColumnType::Time => {
|
||||
let mut cell = Cell::new(&string_column(
|
||||
let mut cell = Cell::new(
|
||||
item.ts
|
||||
.with_timezone(&chrono::Local)
|
||||
.format("%F %T")
|
||||
.to_string(),
|
||||
column_width,
|
||||
));
|
||||
);
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
@@ -172,10 +123,9 @@ pub fn mode_list(
|
||||
}
|
||||
ColumnType::Size => match item.size {
|
||||
Some(size) => {
|
||||
let mut cell = Cell::new(&size_column(
|
||||
let mut cell = Cell::new(format_size(
|
||||
size as u64,
|
||||
settings.human_readable,
|
||||
column_width,
|
||||
));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
@@ -208,8 +158,7 @@ pub fn mode_list(
|
||||
}
|
||||
},
|
||||
ColumnType::Compression => {
|
||||
let mut cell =
|
||||
Cell::new(&string_column(item.compression.to_string(), column_width));
|
||||
let mut cell = Cell::new(item.compression.to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
@@ -222,10 +171,9 @@ pub fn mode_list(
|
||||
}
|
||||
ColumnType::FileSize => match item_path.metadata() {
|
||||
Ok(metadata) => {
|
||||
let mut cell = Cell::new(&size_column(
|
||||
let mut cell = Cell::new(format_size(
|
||||
metadata.len(),
|
||||
settings.human_readable,
|
||||
column_width,
|
||||
));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
@@ -253,10 +201,9 @@ pub fn mode_list(
|
||||
}
|
||||
},
|
||||
ColumnType::FilePath => {
|
||||
let mut cell = Cell::new(&string_column(
|
||||
let mut cell = Cell::new(
|
||||
item_path.clone().into_os_string().into_string().unwrap(),
|
||||
column_width,
|
||||
));
|
||||
);
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
@@ -268,7 +215,7 @@ pub fn mode_list(
|
||||
cell
|
||||
}
|
||||
ColumnType::Tags => {
|
||||
let mut cell = Cell::new(&string_column(tags.join(" "), column_width));
|
||||
let mut cell = Cell::new(tags.join(" "));
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
@@ -282,8 +229,7 @@ pub fn mode_list(
|
||||
ColumnType::Meta => match meta_name {
|
||||
Some(meta_name) => match meta.get(meta_name) {
|
||||
Some(meta_value) => {
|
||||
let mut cell =
|
||||
Cell::new(&string_column(meta_value.to_string(), column_width));
|
||||
let mut cell = Cell::new(meta_value.to_string());
|
||||
match column.align {
|
||||
crate::config::ColumnAlignment::Right => {
|
||||
cell = cell.set_alignment(CellAlignment::Right);
|
||||
|
||||
Reference in New Issue
Block a user