1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//! # Table Formatting and Display Module
//!
//! This module handles the formatting and colorized display of file listings in table format.
//! It uses the `tabled` crate to create well-formatted, colored tables that are easy to read
//! and visually appealing.
//!
//! ## Key Components
//!
//! - [`DisplayEntry`]: Internal struct for table formatting (derived from [`FileEntry`])
//! - [`format_table`]: Main function for rendering and formatting tables as strings
//!
//! ## Features
//!
//! * **Colorized Output**: Different colors for columns (names, sizes, dates, headers)
//! * **Rounded Borders**: Uses rounded table style for modern appearance
//! * **Custom Column Names**: User-friendly column headers
//! * **Flexible Formatting**: Automatically adjusts to terminal width
//!
//! ## Color Scheme
//!
//! The table uses a carefully chosen color scheme for optimal readability:
//!
//! - **Names (Column 1)**: Bright Cyan - Makes filenames stand out
//! - **Sizes (Column 3)**: Bright Magenta - Highlights file sizes
//! - **Dates (Column 4)**: Bright Yellow - Makes modification times visible
//! - **Headers (First Row)**: Bright Green - Clearly separates column headers
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```rust
//! use bestls::table::format_table;
//! use bestls::fsops::{get_files, FileEntry};
//! use std::path::Path;
//!
//! let path = Path::new(".");
//! let files = get_files(&path, false)?;
//!
//! // Format and print table
//! let output = format_table(&files, None, false, true);
//! println!("{}", output);
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! ### Sample Output
//!
//! ```text
//! ╭────────────┬───────────┬────────┬─────────────────────────┬─────────────┬───────┬───────╮
//! │ Name │ Type │ Size │ Modified │ Permissions │ Owner │ Group │
//! ├────────────┼───────────┼────────┼─────────────────────────┼─────────────┼───────┼───────┤
//! │ Cargo.toml │ File │ 1.1 KB │ Thu 22 Aug 2024 17:44:23│ rw-r--r-- │ user │ staff │
//! │ src │ Directory │ 128 B │ Thu 22 Aug 2024 17:44:23│ rwxr-xr-x │ user │ staff │
//! │ README.md │ File │ 4.8 KB │ Thu 22 Aug 2024 17:44:23│ rw-r--r-- │ user │ staff │
//! ╰────────────┴───────────┴────────┴─────────────────────────┴─────────────┴───────┴───────╯
//! ```
//!
//! ## Design Choices
//!
//! ### Internal DisplayEntry Struct
//!
//! The module uses an internal [`DisplayEntry`] struct rather than implementing [`Tabled`]
//! directly on [`FileEntry`] for several reasons:
//!
//! 1. **Separation of Concerns**: Keeps formatting logic separate from data structures
//! 2. **Customization**: Allows custom column names and ordering without affecting core data
//! 3. **Future Flexibility**: Easy to modify display without changing serialization
//!
//! ### Color Selection
//!
//! Colors were chosen to:
//! - Provide good contrast on both light and dark terminals
//! - Help users quickly identify different types of information
//! - Maintain professional appearance while being visually helpful
use crateTheme;
use crateFileEntry;
use HashSet;
use ;
use Style;
use ;
/// Internal representation of a file entry optimized for table display.
///
/// This struct is derived from [`FileEntry`] and is specifically designed for use with
/// the `tabled` crate. It provides custom column names and ordering for optimal
/// table presentation.
///
/// # Fields
///
/// All fields are strings optimized for display:
///
/// * `name` - Filename (displayed as "Name")
/// * `e_type` - File type as string (displayed as "Type")
/// * `human_size` - Human-readable size (displayed as "Size")
/// * `modified` - Formatted modification time (displayed as "Modified")
/// * `permissions` - Permission string (displayed as "Permissions")
/// * `owner` - Owner name (displayed as "Owner")
/// * `group` - Group name (displayed as "Group")
///
/// # Design
///
/// This struct is intentionally kept private as it's an implementation detail.
/// External code should use [`format_table`] to create output strings that can be printed.
///
/// # Attributes
///
/// Uses `tabled(rename = "...")` attributes to provide user-friendly column headers
/// that are more readable than the field names.
/// Display a collection of file entries as a colorized, formatted table.
///
/// This function takes a vector of [`FileEntry`] structs and renders them as a beautiful,
/// colorized table with rounded borders. It's the primary output method for bestls when
/// not using JSON format.
///
/// # Arguments
///
/// * `entries` - Vector of file entries to display
///
/// # Output Format
///
/// The table includes the following columns:
///
/// 1. **Name** (Bright Cyan) - Filename or directory name
/// 2. **Type** - File type (File, Directory, Symlink)
/// 3. **Size** (Bright Magenta) - Human-readable file size
/// 4. **Modified** (Bright Yellow) - Modification date and time
/// 5. **Permissions** - File permissions string
/// 6. **Owner** - File owner name
/// 7. **Group** - File group name
///
/// # Styling
///
/// * **Borders**: Rounded style with Unicode box-drawing characters
/// * **Headers**: Bright green for clear separation
/// * **Colors**: Carefully chosen for readability on various terminal themes
///
/// # Examples
///
/// ## Basic Table Display
///
/// ```rust
/// use bestls::table::format_table;
/// use bestls::fsops::{get_files, FileEntry, FileType};
/// use std::path::Path;
///
/// // Get files from current directory
/// let path = Path::new(".");
/// let files = get_files(&path, false)?;
///
/// // Format as a table string with default theme
/// let output = format_table(&files, None, false, true, None);
/// println!("{}", output);
/// # Ok::<(), std::io::Error>(())
/// ```
///
/// ## With Custom File Entries
///
/// ```rust
/// use bestls::table::format_table;
/// use bestls::fsops::{FileEntry, FileType};
///
/// let entries = vec![
/// FileEntry {
/// name: "document.txt".to_string(),
/// e_type: FileType::File,
/// len_bytes: 1024,
/// human_size: "1.0 KB".to_string(),
/// modified: "Thu 22 Aug 2024 14:30:25".to_string(),
/// permissions: "rw-r--r--".to_string(),
/// owner: "user".to_string(),
/// group: "staff".to_string(),
/// }
/// ];
///
/// let output = format_table(&entries, None, false, true, None);
/// println!("{}", output);
/// ```
///
/// # Performance
///
/// This function is designed for interactive use and prioritizes readability over performance.
/// For large numbers of files (thousands), consider using JSON output instead for better
/// performance and programmatic processing.
///
/// # Terminal Compatibility
///
/// The table uses Unicode box-drawing characters which are supported by most modern terminals.
/// Colors use ANSI escape codes that work with virtually all terminal emulators.
///
/// # Empty Input
///
/// If provided with an empty vector, the function will display an empty table with just headers:
///
/// ```text
/// ╭──────┬──────┬──────┬──────────┬─────────────┬───────┬───────╮
/// │ Name │ Type │ Size │ Modified │ Permissions │ Owner │ Group │
/// ╰──────┴──────┴──────┴──────────┴─────────────┴───────┴───────╯
/// ```
/// Parse column names from comma-separated string.
///
/// # Arguments
/// * `cols` - Comma-separated column specification (e.g., "name,size,date")
///
/// # Returns
/// A HashSet of valid column names
///
/// # Note
/// This function is reserved for future column filtering implementation.
/// Format compact output as string (internal helper)
/// Format table output as a string
///
/// # Arguments
/// * `entries` - Vector of file entries to format
/// * `columns` - Optional column selection (reserved for future use)
/// * `compact` - If true, return single-column format
/// * `use_color` - If true, apply color styling
/// * `theme` - Optional theme for colors (uses default if None)