|
8 | 8 | use std::iter; |
9 | 9 | #[cfg(windows)] |
10 | 10 | use std::os::windows::fs::MetadataExt; |
11 | | -use std::{cell::OnceCell, num::IntErrorKind}; |
| 11 | +use std::{cell::LazyCell, cell::OnceCell, num::IntErrorKind}; |
12 | 12 | use std::{ |
13 | 13 | cmp::Reverse, |
14 | 14 | ffi::{OsStr, OsString}, |
@@ -2577,8 +2577,15 @@ fn display_items( |
2577 | 2577 | // whether text will wrap or not, because when format is grid or |
2578 | 2578 | // column ls will try to place the item name in a new line if it |
2579 | 2579 | // wraps. |
2580 | | - let cell = |
2581 | | - display_item_name(i, config, prefix_context, more_info, out, style_manager, 0); |
| 2580 | + let cell = display_item_name( |
| 2581 | + i, |
| 2582 | + config, |
| 2583 | + prefix_context, |
| 2584 | + more_info, |
| 2585 | + out, |
| 2586 | + style_manager, |
| 2587 | + LazyCell::new(Box::new(|| 0)), |
| 2588 | + ); |
2582 | 2589 |
|
2583 | 2590 | names_vec.push(cell); |
2584 | 2591 | } |
@@ -2870,7 +2877,9 @@ fn display_item_long( |
2870 | 2877 | String::new(), |
2871 | 2878 | out, |
2872 | 2879 | style_manager, |
2873 | | - ansi_width(&String::from_utf8_lossy(&output_display)), |
| 2880 | + LazyCell::new(Box::new(|| { |
| 2881 | + ansi_width(&String::from_utf8_lossy(&output_display)) |
| 2882 | + })), |
2874 | 2883 | ); |
2875 | 2884 |
|
2876 | 2885 | let displayed_item = if quoted && !os_str_starts_with(&item_name, b"'") { |
@@ -2964,7 +2973,9 @@ fn display_item_long( |
2964 | 2973 | String::new(), |
2965 | 2974 | out, |
2966 | 2975 | style_manager, |
2967 | | - ansi_width(&String::from_utf8_lossy(&output_display)), |
| 2976 | + LazyCell::new(Box::new(|| { |
| 2977 | + ansi_width(&String::from_utf8_lossy(&output_display)) |
| 2978 | + })), |
2968 | 2979 | ); |
2969 | 2980 | let date_len = 12; |
2970 | 2981 |
|
@@ -3198,13 +3209,13 @@ fn display_item_name( |
3198 | 3209 | more_info: String, |
3199 | 3210 | out: &mut BufWriter<Stdout>, |
3200 | 3211 | style_manager: &mut Option<StyleManager>, |
3201 | | - current_column: usize, |
| 3212 | + current_column: LazyCell<usize, Box<dyn FnOnce() -> usize + '_>>, |
3202 | 3213 | ) -> OsString { |
3203 | 3214 | // This is our return value. We start by `&path.display_name` and modify it along the way. |
3204 | 3215 | let mut name = escape_name(&path.display_name, &config.quoting_style); |
3205 | 3216 |
|
3206 | 3217 | let is_wrap = |
3207 | | - |namelen: usize| config.width != 0 && current_column + namelen > config.width.into(); |
| 3218 | + |namelen: usize| config.width != 0 && *current_column + namelen > config.width.into(); |
3208 | 3219 |
|
3209 | 3220 | if config.hyperlink { |
3210 | 3221 | name = create_hyperlink(&name, path); |
|
0 commit comments