TerminalUI

Struct TerminalUI 

Source
pub struct TerminalUI {
    pub(super) state: UIState,
    pub(super) chat_mode: ChatMode,
    pub(super) log_mode: LogMode,
    pub(super) event_rx: UnboundedReceiver<UIEvent>,
    pub(super) action_tx: UnboundedSender<UIAction>,
    pub(super) node: Option<Arc<Node>>,
    pub(super) log_buffer: Option<Arc<LogBuffer>>,
}
Expand description

Manages the terminal user interface, including state, rendering, and event handling.

Fields§

§state: UIState

The current state of the user interface.

§chat_mode: ChatMode

The chat mode specific logic and state.

§log_mode: LogMode

The log mode specific logic and state.

§event_rx: UnboundedReceiver<UIEvent>

Receiver for UI events from various parts of the application.

§action_tx: UnboundedSender<UIAction>

Sender for dispatching UI actions.

§node: Option<Arc<Node>>

An optional reference to the application’s core Node.

§log_buffer: Option<Arc<LogBuffer>>

An optional reference to the LogBuffer.

Implementations§

Source§

impl TerminalUI

Source

pub fn new( event_rx: UnboundedReceiver<UIEvent>, action_tx: UnboundedSender<UIAction>, ) -> Self

Creates a new TerminalUI instance.

§Arguments
  • event_rx - The receiver for UIEvents.
  • action_tx - The sender for UIActions.
Source

pub fn set_node(&mut self, node: Arc<Node>)

Sets the application’s core Node.

Source

pub fn set_log_buffer(&mut self, log_buffer: Arc<LogBuffer>)

Sets the LogBuffer for the UI.

Source

pub fn update_friends(&mut self, friends: Vec<String>)

Updates the list of friends in the chat mode’s completer.

Source

pub fn update_discovered_peers(&mut self, peers: Vec<String>)

Updates the list of discovered peers in the chat mode’s completer.

Source

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

Preloads initial messages into the UI state.

This is typically used to display recent message history on startup.

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

pub async fn run(&mut self) -> Result<()>

Runs the main event loop for the terminal UI.

This function continuously listens for UI events, handles them, and re-renders the terminal display.

§Errors

Returns an error if terminal initialization fails or if an unrecoverable error occurs within the event handling or rendering loop.

Source§

impl TerminalUI

Source

pub(super) async fn handle_event(&mut self, event: UIEvent) -> Result<()>

Handles an incoming UIEvent, updating the UI state accordingly.

This function processes various types of events such as new messages, log batches, key presses, and terminal resizes.

§Arguments
  • event - The UIEvent to handle.
§Errors

Returns an error if handling a key event fails.

Source

async fn handle_key_event(&mut self, key: KeyEvent) -> Result<()>

Handles a keyboard KeyEvent.

This function processes key presses, handling special key combinations for mode switching or exiting the application, and then delegates regular key presses to the current UI mode’s handler.

§Arguments
  • key - The KeyEvent to handle.
§Errors

Returns an error if the current UI mode’s key handler fails.

Source§

impl TerminalUI

Source

pub(super) fn initialize_terminal(&mut self) -> Result<()>

Initializes the terminal for TUI mode.

This function enables raw mode, enters the alternate screen, hides the cursor, and captures the initial terminal size.

§Errors

Returns an error if terminal setup fails.

Source

pub fn cleanup(&mut self) -> Result<()>

Cleans up the terminal, restoring it to its original state.

This function disables raw mode, leaves the alternate screen, and shows the cursor.

§Errors

Returns an error if terminal cleanup fails.

Source§

impl TerminalUI

Source

pub(super) fn render(&mut self) -> Result<()>

Renders the entire terminal UI.

This function clears the screen, then renders the appropriate main view (chat or logs), the status line, and the input area.

§Arguments
  • stdout - A mutable reference to the output stream.
§Errors

Returns an error if writing to the output stream fails.

Source

fn render_status_line( &self, stdout: &mut impl Write, row: u16, width: u16, ) -> Result<()>

Renders the status line at the bottom of the message area.

This line displays the current UI mode, connected peer count, and mode-specific tips.

§Arguments
  • stdout - A mutable reference to the output stream.
  • row - The row where the status line should be rendered.
  • width - The width of the terminal.
§Errors

Returns an error if writing to the output stream fails.

Source

fn render_input_area( &self, stdout: &mut impl Write, row: u16, width: u16, height: u16, ) -> Result<()>

Renders the input area where the user types commands or messages.

This includes the input prompt, the current input buffer, and any autocompletion suggestions. Also renders help text.

§Arguments
  • stdout - A mutable reference to the output stream.
  • row - The starting row for the input area.
  • width - The width of the terminal.
  • height - The height of the input area.
§Errors

Returns an error if writing to the output stream fails.

Trait Implementations§

Source§

impl Drop for TerminalUI

Source§

fn drop(&mut self)

Cleans up the terminal when the TerminalUI instance is dropped.

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,