Skip to main content

TuiState

Struct TuiState 

Source
pub struct TuiState {
Show 24 fields pub pending_hat: Option<(HatId, String)>, pub pending_backend: Option<String>, pub iteration: u32, pub prev_iteration: u32, pub loop_started: Option<Instant>, pub iteration_started: Option<Instant>, pub last_event: Option<String>, pub last_event_at: Option<Instant>, pub show_help: bool, pub in_scroll_mode: bool, pub search_query: String, pub search_forward: bool, pub max_iterations: Option<u32>, pub idle_timeout_remaining: Option<Duration>, pub iterations: Vec<IterationBuffer>, pub current_view: usize, pub following_latest: bool, pub new_iteration_alert: Option<usize>, pub search_state: SearchState, pub loop_completed: bool, pub final_iteration_elapsed: Option<Duration>, pub final_loop_elapsed: Option<Duration>, pub task_counts: TaskCounts, pub active_task: Option<TaskSummary>, /* private fields */
}
Expand description

Observable state derived from loop events.

Fields§

§pending_hat: Option<(HatId, String)>

Which hat will process next event (ID + display name).

§pending_backend: Option<String>

Backend expected for the next iteration (used when metadata is missing).

§iteration: u32

Current iteration number (0-indexed, display as +1).

§prev_iteration: u32

Previous iteration number (for detecting changes).

§loop_started: Option<Instant>

When loop began.

§iteration_started: Option<Instant>

When current iteration began.

§last_event: Option<String>

Most recent event topic.

§last_event_at: Option<Instant>

Timestamp of last event.

§show_help: bool

Whether to show help overlay.

§in_scroll_mode: bool

Whether in scroll mode.

§search_query: String

Current search query (if in search input mode).

§search_forward: bool

Search direction (true = forward, false = backward).

§max_iterations: Option<u32>

Maximum iterations from config.

§idle_timeout_remaining: Option<Duration>

Idle timeout countdown.

§iterations: Vec<IterationBuffer>

Content buffers for each iteration.

§current_view: usize

Index of the iteration currently being viewed (0-indexed).

§following_latest: bool

Whether to automatically follow the latest iteration.

§new_iteration_alert: Option<usize>

Alert about a new iteration (shown when viewing history and new iteration arrives). Contains the iteration number to alert about. Cleared when navigating to latest.

§search_state: SearchState

Search state for finding and navigating matches in iteration content.

§loop_completed: bool

Whether the loop has completed (received loop.terminate event).

§final_iteration_elapsed: Option<Duration>

Frozen elapsed time when loop completed (timer stops at this value).

§final_loop_elapsed: Option<Duration>

Frozen total elapsed time when loop completed (footer timer stops).

§task_counts: TaskCounts

Aggregate task counts for display in TUI widgets.

§active_task: Option<TaskSummary>

Currently active task (if any) for display in TUI widgets.

Implementations§

Source§

impl TuiState

Source

pub fn new() -> Self

Creates empty state. Timer starts immediately at creation.

Source

pub fn with_hat_map(hat_map: HashMap<String, (HatId, String)>) -> Self

Creates state with a custom hat map for dynamic topic-to-hat resolution. Timer starts immediately at creation.

Source

pub fn update(&mut self, event: &Event)

Updates state based on event topic.

Source

pub fn get_pending_hat_display(&self) -> String

Returns formatted hat display (emoji + name).

Source

pub fn get_loop_elapsed(&self) -> Option<Duration>

Time since loop started.

Source

pub fn get_iteration_elapsed(&self) -> Option<Duration>

Time since iteration started, or frozen value if loop completed.

Source

pub fn is_active(&self) -> bool

True if event received in last 2 seconds.

Source

pub fn iteration_changed(&self) -> bool

True if iteration changed since last check.

Source

pub fn get_task_counts(&self) -> &TaskCounts

Returns a reference to the current task counts.

Source

pub fn get_active_task(&self) -> Option<&TaskSummary>

Returns a reference to the active task, if any.

Source

pub fn set_task_counts(&mut self, counts: TaskCounts)

Updates the task counts.

Source

pub fn set_active_task(&mut self, task: Option<TaskSummary>)

Sets the active task.

Source

pub fn has_open_tasks(&self) -> bool

Returns true if there are any open tasks.

Source

pub fn get_task_progress_display(&self) -> String

Returns a formatted string for task progress display (e.g., “3/5 tasks”).

Source

pub fn start_new_iteration(&mut self)

Starts a new iteration, creating a new IterationBuffer. If following_latest is true, current_view is updated to the new iteration. If not following, sets the new_iteration_alert to notify the user.

Source

pub fn start_new_iteration_with_metadata( &mut self, hat_display: Option<String>, backend: Option<String>, )

Starts a new iteration with optional metadata for hat and backend display.

Source

pub fn finish_latest_iteration(&mut self)

Finalizes the latest iteration’s elapsed time if it isn’t already set.

Source

pub fn current_iteration_hat_display(&self) -> Option<&str>

Returns the hat display for the currently viewed iteration, if available.

Source

pub fn current_iteration_backend(&self) -> Option<&str>

Returns the backend display for the currently viewed iteration, if available.

Source

pub fn current_iteration(&self) -> Option<&IterationBuffer>

Returns a reference to the currently viewed iteration buffer.

Source

pub fn current_iteration_mut(&mut self) -> Option<&mut IterationBuffer>

Returns a mutable reference to the currently viewed iteration buffer.

Source

pub fn current_iteration_lines_handle( &self, ) -> Option<Arc<Mutex<Vec<Line<'static>>>>>

Returns a shared handle to the current iteration’s lines buffer.

This allows stream handlers to write directly to the buffer, enabling real-time streaming to the TUI during execution.

Source

pub fn latest_iteration_lines_handle( &self, ) -> Option<Arc<Mutex<Vec<Line<'static>>>>>

Returns a shared handle to the latest iteration’s lines buffer.

This should be used when writing output from the currently executing iteration, regardless of which iteration the user is viewing. This prevents output from being written to the wrong iteration when the user is reviewing an older iteration.

Source

pub fn navigate_next(&mut self)

Navigates to the next iteration (if not at the last one). If reaching the last iteration, re-enables following_latest and clears alerts.

Source

pub fn navigate_prev(&mut self)

Navigates to the previous iteration (if not at the first one). Disables following_latest when navigating backwards.

Source

pub fn total_iterations(&self) -> usize

Returns the total number of iterations.

Source

pub fn search(&mut self, query: &str)

Searches for the given query in the current iteration’s content. Populates matches with (line_index, char_offset) pairs. Search is case-insensitive.

Source

pub fn next_match(&mut self)

Navigates to the next match, cycling back to the first if at the end.

Source

pub fn prev_match(&mut self)

Navigates to the previous match, cycling to the last if at the beginning.

Clears the search state.

Trait Implementations§

Source§

impl Default for TuiState

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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