Skip to main content

LogViewer

Struct LogViewer 

Source
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

Source

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.
Source

pub fn wrap_mode(self, mode: LogWrapMode) -> Self

Set the wrap mode.

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.

Source

pub fn style(self, style: Style) -> Self

Set the default style for lines.

Source

pub fn highlight_style(self, style: Style) -> Self

Set the highlight style for selected lines.

Source

pub fn search_highlight_style(self, style: Style) -> Self

Set the highlight style for search matches within lines.

Source

pub fn len(&self) -> usize

Returns the total number of log lines.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no log lines.

Source

pub fn push<'a>(&mut self, line: impl Into<FtuiText<'a>>)

Append a single log line.

§Performance
  • O(1) amortized for append
  • O(1) for eviction when at capacity
§Auto-scroll Behavior

If follow mode is enabled, view stays at bottom after push.

Source

pub fn push_many<'a>( &mut self, lines: impl IntoIterator<Item = impl Into<FtuiText<'a>>>, )

Append multiple lines efficiently.

Source

pub fn scroll_up(&mut self, lines: usize)

Scroll up by N lines. Disables follow mode.

Source

pub fn scroll_down(&mut self, lines: usize)

Scroll down by N lines. Re-enables follow mode if at bottom.

Source

pub fn scroll_to_top(&mut self)

Jump to top of log history. Disables follow mode.

Source

pub fn scroll_to_bottom(&mut self)

Jump to bottom and re-enable follow mode.

Source

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.

Source

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.

Source

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).

Source

pub fn line_count(&self) -> usize

Total line count in buffer.

Source

pub fn auto_scroll_enabled(&self) -> bool

Check if follow mode (auto-scroll) is enabled.

Source

pub fn set_auto_scroll(&mut self, enabled: bool)

Set follow mode (auto-scroll) state.

Source

pub fn toggle_follow(&mut self)

Toggle follow mode on/off.

Source

pub fn clear(&mut self)

Clear all lines.

Source

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.

Source

pub fn filter_stats_mut(&mut self) -> &mut FilterStats

Get a mutable reference to the filter statistics (for resetting).

Source

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.

Source

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.

Source

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.

Source

pub fn next_match(&mut self)

Jump to next search match.

Source

pub fn prev_match(&mut self)

Jump to previous search match.

Clear active search.

Source

pub fn search_info(&self) -> Option<(usize, usize)>

Get current search match info: (current_match_1indexed, total_matches).

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for LogViewer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogViewer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for LogViewer

Source§

type State = LogViewerState

The state type associated with this widget.
Source§

fn render(&self, area: Rect, frame: &mut Frame<'_>, state: &mut Self::State)

Render the widget into the frame, potentially modifying state. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more