| 680 | } |
| 681 | |
| 682 | fn slice_lines(text: &str, start: usize, end: Option<usize>) -> String { |
| 683 | let lines: Vec<&str> = text.lines().collect(); |
| 684 | if lines.is_empty() { |
| 685 | return String::new(); |
| 686 | } |
| 687 | |
| 688 | let start_idx = start.saturating_sub(1).min(lines.len()); |
| 689 | let end_idx = end.unwrap_or(lines.len()).min(lines.len()); |
| 690 | if start_idx >= end_idx { |
| 691 | return String::new(); |
| 692 | } |
| 693 | |
| 694 | lines[start_idx..end_idx].join("\n") |
| 695 | } |
| 696 | |
| 697 | async fn read_directory_preview(path: &Path) -> String { |
| 698 | let mut entries = match tokio::fs::read_dir(path).await { |