Requests Tab
Relevant source files
The following files were used as context for generating this wiki page:
The Requests Tab is a core component of the LogUtil terminal user interface (TUI) designed to provide a searchable, paginated, and real-time view of processed Nginx log entries. It allows users to browse through large datasets of log records with interactive filtering and navigation capabilities.
As a primary monitoring tool within the application, it interfaces with the global memory database to retrieve and display raw log lines. Users can filter results via a search bar, navigate through results using a dedicated pagination system, and copy specific log entries to the system clipboard for further analysis.
Sources: README.md:213-216, src/tabs/requests.rs:1-25
Architecture and UI Components
The Requests Tab is implemented as a struct that fulfills the Tab trait requirements. It manages its own internal state, including table selection, search input, and pagination progress.
Structural Components
The UI is divided into three main logical areas:
- Search Bar: A text input field at the top-left that filters log entries in real-time.
- Pagination Bar: A tab-style selector at the top-right that allows users to switch between different sets of results.
- Request List: A central table displaying the content of the log entries based on the current search and page selection.
Sources: src/tabs/requests.rs:43-107
Data Flow Diagram
The following diagram illustrates how the Requests Tab interacts with the global database and the user interface to display information.
Key Logic and Data Structures
Tab State Management
The RequestsTab struct maintains the state necessary to render the interactive elements and manage large datasets.
| Field | Type | Description |
|---|---|---|
table_state | TableState | Manages the scroll position and selection index of the main request list. |
input | String | Stores the current character sequence typed by the user for filtering. |
current_page | usize | Tracks the index of the currently active page in the results view. |
total_pages | usize | Calculated value based on the number of filtered results and items_per_page. |
Sources: src/tabs/requests.rs:20-25, src/tabs/requests.rs:156-165
Interaction Handling
The tab processes keyboard events to allow dynamic interaction without leaving the main interface.
Sources: src/tabs/requests.rs:205-255
Implementation Details
Search and Pagination Logic
Filtering is performed by iterating through the GLOBAL_DB records and checking if the log_line contains the case-insensitive search string. Pagination is hardcoded to show 30 items per page to ensure readability within the TUI constraints.
fn get_search_results(&mut self) -> Vec<String> {
let db = &*GLOBAL_DB;
let records = db.get_all_records();
let all_results: Vec<String> = records.iter().map(|record| record.log_line.clone()).collect();
if self.input.is_empty() {
all_results
} else {
all_results
.iter()
.filter(|record| record.to_lowercase().contains(&self.input.to_lowercase()))
.cloned()
.collect()
}
}
Sources: src/tabs/requests.rs:110-125, src/tabs/requests.rs:156-157
Clipboard Integration
When a user selects a row and presses Enter, the copy_selected_to_clipboard function is triggered. This uses the arboard crate to interact with the system clipboard, allowing the raw log line to be pasted into other applications.
Sources: src/tabs/requests.rs:140-153, src/app.rs:117-130
Conclusion
The Requests Tab serves as the primary data-inspection interface for LogUtil. By combining real-time filtering from the global database with a paginated table view, it provides a performant way to analyze thousands of log entries directly from the terminal. Its integration with system services like the clipboard makes it a versatile tool for technical troubleshooting and log analysis.
Sources: README.md:213-216, src/tabs/requests.rs:1-25