Interactive File Selection
Relevant source files
The following files were used as context for generating this wiki page:
Interactive File Selection is a specialized mode within LogUtil that allows users to navigate their local file system and configure analysis parameters through a Terminal User Interface (TUI) before starting the log processing engine. This mode is automatically triggered when the application is launched without a specific file path argument. Sources: src/main.rs:114-124, README.md:58-60
The system provides a split-pane interface: a directory browser for locating Nginx or Apache access logs and a configuration panel for fine-tuning parsing logic, such as regex patterns and date formats. Once a file is selected and settings are finalized, the system transitions from the selection state to the real-time analysis state. Sources: src/file_settings.rs:198-208, README.md:69-76
Architecture and Components
The interactive mode is managed primarily by the FileSettings struct, which encapsulates the state for both file system navigation and application configuration. Sources: src/file_settings.rs:49-74
Core Data Structures
| Component | Description | Data Structure |
|---|---|---|
| File Browser | Manages current directory path and items (files/folders). | Vec<FileItem> |
| Settings Registry | Stores configurable parameters like regex and tab toggles. | Vec<Setting> |
| State Management | Tracks active panel, table selections, and modal warnings. | TableState, active_panel |
| Input Handling | Manages text input buffers for editing configuration values. | input_mode, current_input |
Sources: src/file_settings.rs:50-74
Component Interaction Flow
The following diagram illustrates how the run_interactive_mode function orchestrates the lifecycle of the selection interface:
File System Navigation
The navigation component allows users to traverse directories using std::fs. It identifies parent directories, subdirectories, and files, providing metadata such as size and modification time. Sources: src/file_settings.rs:112-196
Navigation Logic
- Directory Loading: The
load_directoryfunction populates the browser list, always inserting a..entry if a parent path exists. Sources: src/file_settings.rs:113-116 - Sorting: Items are sorted with directories prioritized at the top, followed by files in alphabetical order. Sources: src/file_settings.rs:185-193
- Visual Feedback: The interface uses icons (📁 for folders, 📄 for files, ⬆️ for parent) and color-coded highlights to indicate selection. Sources: src/file_settings.rs:232-243, README.md:62-66
Configuration Management
The right pane of the interactive mode allows users to modify CliArgs before the analysis begins. This ensures that custom log formats or specific analysis modules can be enabled without restarting the application with complex CLI flags. Sources: src/file_settings.rs:85-110
Configurable Parameters
| Setting Name | Type | Description |
|---|---|---|
| Count | Number | Lines to read from the end (0=tail, -1=all). |
| Regex Pattern | Regex | Pattern used to extract IP, Date, URL, etc. |
| Date Format | Text | Format string for chrono parsing. |
| Top N | Number | Limits the number of entries in the Overview tab. |
| Enable Security | Boolean | Toggles the Security analysis module. |
| Enable Performance | Boolean | Toggles response time tracking. |
Sources: src/file_settings.rs:88-110, README.md:195-212
Input Processing Sequence
The system uses a state machine to handle input, switching between "Navigation Mode" and "Input Mode."
Interaction Controls
The system supports both keyboard and mouse interactions to facilitate quick file selection.
Input Mapping
- Panel Switching:
TaborLeft/Rightarrow keys toggle focus between the File Browser and the Settings panel. Sources: src/file_settings.rs:637-646 - Selection:
Enterin the browser enters a directory or selects a file. In the settings panel, it toggles booleans or enters text edit mode. Sources: src/file_settings.rs:696-749 - Mouse Support: Left-clicking selects items; double-clicking a file immediately initiates the analysis. Sources: src/file_settings.rs:412-423, src/file_settings.rs:480-498
- Execution: The
F10key or the "▶ Start Analysis" button triggers the transition to the main application state. Sources: src/file_settings.rs:360-366, src/file_settings.rs:730-740
Modal Messaging
To ensure technical accuracy and prevent runtime crashes, the FileSettings system includes a modal warning system. If a user attempts to start an analysis without selecting a file, or if the selected path becomes invalid, a popup is rendered using the TuiManager. Sources: src/file_settings.rs:842-888, src/tui_manager.rs:70-111
pub fn show_modal(&mut self, message: String) {
self.modal_state = Some(ModalState {
message,
show_until: Some(Instant::now() + std::time::Duration::from_millis(2000)),
});
}
Sources: src/file_settings.rs:835-840
Conclusion
The Interactive File Selection system provides a user-friendly bridge between the command line and the high-performance analysis engine. By consolidating directory navigation and parameter configuration into a unified TUI, LogUtil allows for flexible log monitoring without requiring users to memorize complex regular expressions or CLI syntax. Sources: README.md:58-76