Skip to content

Commit

Permalink
temp remove shortening from short format
Browse files Browse the repository at this point in the history
  • Loading branch information
seapagan committed Feb 10, 2025
1 parent b569ddc commit 9ce6732
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
31 changes: 11 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,10 @@ fn run_multi(patterns: &[String], params: &Params) -> io::Result<()> {
if params.long_format {
display_long_format(&all_file_info, params, terminal_width)
} else {
display_short_format(&all_file_info, params, terminal_width)
display_short_format(&all_file_info, params)
}
}

// fn handle_error(path: &str, e: io::Error) {
// let error_message = match e.kind() {
// io::ErrorKind::PermissionDenied => "Permission denied",
// io::ErrorKind::NotFound => "No such file or directory",
// _ => &e.to_string(),
// };
// eprintln!("lsp: {}: {}", path, error_message);
// }

fn calculate_column_widths(
file_info: &[FileInfo],
params: &Params,
Expand Down Expand Up @@ -235,8 +226,7 @@ fn display_long_format(

fn display_short_format(
file_info: &[FileInfo],
params: &Params,
terminal_width: usize,
_params: &Params,
) -> io::Result<()> {
// Strip ANSI codes when calculating length
let max_name_length = file_info
Expand All @@ -251,21 +241,22 @@ fn display_short_format(
.unwrap_or(0)
+ 2; // Adding space between columns

let terminal_width = term_size::dimensions().map(|(w, _)| w).unwrap_or(80);
let num_columns = terminal_width / max_name_length;

let mut table = utils::table::create_table(2);

for chunk in file_info.chunks(num_columns) {
let mut row = Row::empty();
for info in chunk {
let mut display_name = check_display_name(info);
let display_name = check_display_name(info);

// Shorten the filename if needed and the option is enabled
if params.shorten_names {
let max_width = max_name_length - 2; // Account for spacing
display_name =
utils::format::shorten_filename(&display_name, max_width);
}
// if params.shorten_names {
// let max_width = max_name_length - 2; // Account for spacing
// display_name =
// utils::format::shorten_filename(&display_name, max_width);
// }

let mut cell_content = String::new();
if let Some(icon) = &info.item_icon {
Expand Down Expand Up @@ -376,11 +367,11 @@ mod tests {
shorten_names: true,
..Default::default()
};
display_short_format(&file_info, &params, test_width)?;
display_short_format(&file_info, &params)?;

// Test short format without name shortening
let params = Params::default();
display_short_format(&file_info, &params, test_width)?;
display_short_format(&file_info, &params)?;

Ok(())
}
Expand Down
10 changes: 4 additions & 6 deletions src/utils/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use colored::*;

pub fn mode_to_rwx(mode: u32) -> String {
let mut rwx = String::new();
let perms = [
Expand Down Expand Up @@ -65,7 +63,7 @@ pub fn shorten_filename(filename: &str, max_width: usize) -> String {
format!(
"{}{}{}{}",
&name[..start_chars],
"...".red(),
"...",
&name[name.len() - end_chars..],
ext
)
Expand Down Expand Up @@ -200,13 +198,13 @@ mod tests {
// Test basic shortening (balanced between start and end)
assert_eq!(
shorten_filename("verylongfilename.txt", 15),
format!("very{}name.txt", "...".red())
format!("very{}name.txt", "...")
);

// Test with no extension (balanced between start and end)
assert_eq!(
shorten_filename("verylongfilename", 10),
format!("ver{}name", "...".red())
format!("ver{}name", "...")
);

// Test with very short max width
Expand All @@ -218,7 +216,7 @@ mod tests {
// Test with hidden file (balanced between start and end)
assert_eq!(
shorten_filename(".longconfigfile.conf", 15),
format!(".lo{}file.conf", "...".red())
format!(".lo{}file.conf", "...")
);
}
}

0 comments on commit 9ce6732

Please sign in to comment.