pub struct LogViewer { /* private fields */ }Expand description
A scrolling log viewer optimized for streaming append-only content.
Internally uses Virtualized<Text> for storage and scroll management,
adding capacity enforcement, wrapping, filtering, and search on top.
§Design Rationale
- Virtualized handles scroll offset, follow mode, momentum, page navigation
- LogViewer adds max_lines eviction (Virtualized has no built-in capacity limit)
- Separate scroll semantics: Virtualized uses “offset from top”; LogViewer exposes “follow mode” (newest at bottom) as the default behavior
- wrap_mode configurable per-instance for different use cases
- Stateful widget pattern for scroll state preservation across renders
Implementations§
Source§impl LogViewer
impl LogViewer
Sourcepub fn new(max_lines: usize) -> Self
pub fn new(max_lines: usize) -> Self
Create a new LogViewer with specified max line capacity.
§Arguments
max_lines- Maximum lines to retain. When exceeded, oldest lines are evicted. Recommend 10,000-100,000 for typical agent use cases.
Sourcepub fn wrap_mode(self, mode: LogWrapMode) -> Self
pub fn wrap_mode(self, mode: LogWrapMode) -> Self
Set the wrap mode.
Sourcepub fn retain_links_for_last_lines(self, lines: usize) -> Self
pub fn retain_links_for_last_lines(self, lines: usize) -> Self
Keep hyperlink metadata only on the newest lines retained records.
Older records keep their text and styling, but their spans lose link targets. This applies immediately to existing records and after each appended line, including lines within a multi-line push. Zero strips all links. By default, links remain for the full text retention period. Increasing this limit cannot restore targets already removed.
Sourcepub fn highlight_style(self, style: Style) -> Self
pub fn highlight_style(self, style: Style) -> Self
Set the highlight style for selected lines.
Sourcepub fn search_highlight_style(self, style: Style) -> Self
pub fn search_highlight_style(self, style: Style) -> Self
Set the highlight style for search matches within lines.
Sourcepub fn push_many<'a>(
&mut self,
lines: impl IntoIterator<Item = impl Into<FtuiText<'a>>>,
)
pub fn push_many<'a>( &mut self, lines: impl IntoIterator<Item = impl Into<FtuiText<'a>>>, )
Append multiple lines efficiently.
Sourcepub fn scroll_down(&mut self, lines: usize)
pub fn scroll_down(&mut self, lines: usize)
Scroll down by N lines. Re-enables follow mode if at bottom.
Sourcepub fn scroll_to_top(&mut self)
pub fn scroll_to_top(&mut self)
Jump to top of log history. Disables follow mode.
Sourcepub fn scroll_to_bottom(&mut self)
pub fn scroll_to_bottom(&mut self)
Jump to bottom and re-enable follow mode.
Sourcepub fn page_up(&mut self, _state: &LogViewerState)
pub fn page_up(&mut self, _state: &LogViewerState)
Page up (scroll by viewport height).
Uses the visible count tracked by the Virtualized container.
The state parameter is accepted for API compatibility.
Sourcepub fn page_down(&mut self, _state: &LogViewerState)
pub fn page_down(&mut self, _state: &LogViewerState)
Page down (scroll by viewport height).
Uses the visible count tracked by the Virtualized container.
The state parameter is accepted for API compatibility.
Sourcepub fn is_at_bottom(&self) -> bool
pub fn is_at_bottom(&self) -> bool
Check if currently scrolled to the bottom.
Returns true when follow mode is active (even before first render
when the viewport size is unknown).
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Total line count in buffer.
Sourcepub fn auto_scroll_enabled(&self) -> bool
pub fn auto_scroll_enabled(&self) -> bool
Check if follow mode (auto-scroll) is enabled.
Sourcepub fn set_auto_scroll(&mut self, enabled: bool)
pub fn set_auto_scroll(&mut self, enabled: bool)
Set follow mode (auto-scroll) state.
Sourcepub fn toggle_follow(&mut self)
pub fn toggle_follow(&mut self)
Toggle follow mode on/off.
Sourcepub fn filter_stats(&self) -> &FilterStats
pub fn filter_stats(&self) -> &FilterStats
Get a reference to the incremental filter/search statistics.
Use this to monitor how often the streaming incremental path is used versus full rescans.
Sourcepub fn filter_stats_mut(&mut self) -> &mut FilterStats
pub fn filter_stats_mut(&mut self) -> &mut FilterStats
Get a mutable reference to the filter statistics (for resetting).
Sourcepub fn set_filter(&mut self, pattern: Option<&str>)
pub fn set_filter(&mut self, pattern: Option<&str>)
Set a filter pattern (plain substring match).
Only lines containing the pattern will be shown. Pass None to clear.
Sourcepub fn search(&mut self, query: &str) -> usize
pub fn search(&mut self, query: &str) -> usize
Search for text and return match count.
Convenience wrapper using default config (literal, case-sensitive, no context).
Sets up search state for navigation with next_match / prev_match.
Sourcepub fn search_with_config(&mut self, query: &str, config: SearchConfig) -> usize
pub fn search_with_config(&mut self, query: &str, config: SearchConfig) -> usize
Search with full configuration (mode, case sensitivity, context lines).
Returns match count. Sets up state for next_match / prev_match.
Sourcepub fn next_match(&mut self)
pub fn next_match(&mut self)
Jump to next search match.
Sourcepub fn prev_match(&mut self)
pub fn prev_match(&mut self)
Jump to previous search match.
Sourcepub fn clear_search(&mut self)
pub fn clear_search(&mut self)
Clear active search.
Sourcepub fn search_info(&self) -> Option<(usize, usize)>
pub fn search_info(&self) -> Option<(usize, usize)>
Get current search match info: (current_match_1indexed, total_matches).
Sourcepub fn highlight_ranges_for_line(
&self,
line_idx: usize,
) -> Option<&[(usize, usize)]>
pub fn highlight_ranges_for_line( &self, line_idx: usize, ) -> Option<&[(usize, usize)]>
Get the highlight byte ranges for a given line index, if any.
Returns Some(&[(start, end)]) when the line is a search match.
Sourcepub fn context_line_indices(&self) -> Option<&[usize]>
pub fn context_line_indices(&self) -> Option<&[usize]>
Get the context-expanded line indices, if context lines are configured.
Returns None when no search is active or context_lines == 0.
Sourcepub fn search_match_rate_hint(&self) -> f64
pub fn search_match_rate_hint(&self) -> f64
Returns the fraction of recent pushes that matched the active search.
Useful for callers integrating with an EProcessThrottle to decide
when to trigger a full UI refresh vs. deferring.
Returns 0.0 when no search is active or no incremental checks occurred.