UIState

Struct UIState 

Source
pub struct UIState {
Show 15 fields pub mode: UIMode, pub last_log_mode: Option<UIMode>, pub messages: Vec<ChatMessageEntry>, pub chat_messages: Vec<(DateTime<Utc>, String)>, pub logs: VecDeque<LogEntry>, pub scroll_offset: usize, pub log_scroll_offset: usize, pub horizontal_scroll_offset: usize, pub is_at_bottom_chat: bool, pub is_at_bottom_log: bool, pub input_buffer: String, pub cursor_pos: usize, pub terminal_size: (u16, u16), pub max_log_entries: usize, pub connected_peers_count: usize,
}
Expand description

Represents the overall state of the user interface.

This struct holds all the data and configuration necessary to render the UI and respond to user interactions.

Fields§

§mode: UIMode

The current operational mode of the UI (Chat or Logs).

§last_log_mode: Option<UIMode>

Stores the last log mode for easy switching back.

§messages: Vec<ChatMessageEntry>

A vector of chat message entries for display.

§chat_messages: Vec<(DateTime<Utc>, String)>

A vector of generic chat messages, typically system messages or command output.

§logs: VecDeque<LogEntry>

A deque of log entries for the log view.

§scroll_offset: usize

The current vertical scroll offset for the chat view.

§log_scroll_offset: usize

The current vertical scroll offset for the log view.

§horizontal_scroll_offset: usize

The current horizontal scroll offset for text.

§is_at_bottom_chat: bool

Indicates if the chat view is scrolled to the bottom.

§is_at_bottom_log: bool

Indicates if the log view is scrolled to the bottom.

§input_buffer: String

The current content of the input buffer.

§cursor_pos: usize

The current cursor position within the input buffer.

§terminal_size: (u16, u16)

The current size of the terminal (width, height).

§max_log_entries: usize

The maximum number of log entries to retain.

§connected_peers_count: usize

The count of currently connected peers.

Implementations§

Source§

impl UIState

Source

pub fn add_message(&mut self, message: Message)

Adds a new Message to the UI state.

This function stores the message along with its reception timestamp. If the UI is in chat mode and at the bottom of the scroll, it resets the scroll offset. Otherwise, it adjusts the scroll offset to keep new messages visible if not explicitly scrolled up.

§Arguments
  • message - The Message to add.
Source

pub fn add_chat_message(&mut self, message: String)

Adds a generic chat message string to the UI state.

This is typically used for system messages or user input echoes. It handles scroll adjustment similarly to add_message.

§Arguments
  • message - The string content of the chat message.
Source

pub fn add_history_output(&mut self, message: String)

Adds a block of history output to the UI state.

This is used for displaying multi-line output from commands like history. Each line is prefixed with a special marker for rendering purposes.

§Arguments
  • message - The string content of the history output.
Source

pub fn update_chat_scroll_state(&mut self, terminal_height: usize)

Updates the chat scroll state based on the current terminal height.

This ensures that the scroll_offset remains within valid bounds and updates is_at_bottom_chat.

§Arguments
  • terminal_height - The current height of the terminal in lines.
Source

pub fn calculate_total_chat_items(&self) -> usize

Calculates the total number of displayable items in the chat view.

This includes both actual messages and generic chat messages.

§Returns

The total count of items that can be displayed.

Source

pub fn jump_to_bottom_chat(&mut self)

Scrolls the chat view to the bottom.

Source§

impl UIState

Source

pub fn safe_insert_char(&mut self, c: char)

Inserts a character safely into the input buffer at the current cursor position.

Handles multi-byte characters correctly.

§Arguments
  • c - The character to insert.
Source

pub fn safe_remove_char_before(&mut self) -> bool

Removes the character before the current cursor position safely.

Handles multi-byte characters correctly.

§Returns

true if a character was removed, false otherwise.

Source

pub fn safe_remove_char_at(&mut self) -> bool

Removes the character at the current cursor position safely.

Handles multi-byte characters correctly.

§Returns

true if a character was removed, false otherwise.

Source

pub fn safe_cursor_left(&mut self)

Moves the cursor one position to the left.

Source

pub fn safe_cursor_right(&mut self)

Moves the cursor one position to the right.

Source

pub fn safe_cursor_home(&mut self)

Moves the cursor to the beginning of the input buffer.

Source

pub fn safe_cursor_end(&mut self)

Moves the cursor to the end of the input buffer.

Source§

impl UIState

Source

pub fn add_log_batch(&mut self, entries: Vec<LogEntry>)

Adds a batch of new log entries to the UI state.

This function appends new log entries to the buffer, enforcing max_log_entries. If the UI is in log mode and at the bottom of the scroll, it resets the scroll offset. Otherwise, it adjusts the scroll offset to keep new messages visible if not explicitly scrolled up.

§Arguments
  • entries - A Vec of LogEntry to add.
Source

pub fn refresh_logs(&mut self)

Triggers a refresh of the log display.

This function resets the log scroll offset and marks the view as being at the bottom, useful when filter settings change.

Source

pub fn update_log_scroll_state(&mut self, terminal_height: usize)

Updates the log scroll state based on the current terminal height.

This ensures that the log_scroll_offset remains within valid bounds and updates is_at_bottom_log.

§Arguments
  • terminal_height - The current height of the terminal in lines.
Source

pub fn jump_to_bottom_log(&mut self)

Scrolls the log view to the bottom.

Source

pub fn filtered_logs(&self) -> Vec<&LogEntry>

Returns a vector of log entries filtered by the current UIMode::Logs settings.

Logs can be filtered by minimum Level and by a text filter string, which can include exclusions prefixed with -.

Source§

impl UIState

Source

pub fn new() -> Self

Creates a new UIState with default values.

Source

pub fn toggle_mode(&mut self)

Toggles the UI mode between chat and logs.

When switching to log mode for the first time or from chat mode, it initializes log mode settings if not already defined. Resets scroll offsets and is_at_bottom flags upon mode change.

Source

pub fn replace_messages(&mut self, messages: Vec<Message>)

Replaces the current list of displayed messages with a new set.

Resets scroll offset to the bottom after replacing messages.

§Arguments
  • messages - A Vec of Messages to display.
Source

fn contains_message(&self, message_id: &Uuid) -> bool

Checks if a message with the given ID already exists in the UI state.

§Arguments
  • message_id - The Uuid of the message to check.
§Returns

true if the message is found, false otherwise.

Trait Implementations§

Source§

impl Debug for UIState

Source§

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

Formats the value using the given formatter. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,