| 38 | } |
| 39 | |
| 40 | pub(crate) fn format_compact_annotated_path_list<'a, S>( |
| 41 | paths: impl IntoIterator<Item = (&'a str, S)>, |
| 42 | bullet_prefix: &str, |
| 43 | tree_prefix: &str, |
| 44 | ) -> String |
| 45 | where |
| 46 | S: AsRef<str>, |
| 47 | { |
| 48 | let mut root = PathNode::default(); |
| 49 | let mut bullet_lines = Vec::new(); |
| 50 | for (path, suffix) in paths { |
| 51 | let suffix = suffix.as_ref(); |
| 52 | bullet_lines.push(format!("{bullet_prefix}{path}{suffix}")); |
| 53 | root.insert(path, suffix); |
| 54 | } |
| 55 | |
| 56 | let bullet_list = bullet_lines.join("\n"); |
| 57 | let tree = prefix_lines(&render_path_tree(&root), tree_prefix); |
| 58 | if has_directory_shape(&root) && tree.len() < bullet_list.len() { |
| 59 | tree |
| 60 | } else { |
| 61 | bullet_list |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | fn render_path_tree(root: &PathNode) -> String { |
| 66 | let mut lines = Vec::new(); |