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: UIStateThe current state of the user interface.
chat_mode: ChatModeThe chat mode specific logic and state.
log_mode: LogModeThe 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
impl TerminalUI
Sourcepub fn new(
event_rx: UnboundedReceiver<UIEvent>,
action_tx: UnboundedSender<UIAction>,
) -> Self
pub fn new( event_rx: UnboundedReceiver<UIEvent>, action_tx: UnboundedSender<UIAction>, ) -> Self
Creates a new TerminalUI instance.
§Arguments
event_rx- The receiver forUIEvents.action_tx- The sender forUIActions.
Sourcepub fn set_log_buffer(&mut self, log_buffer: Arc<LogBuffer>)
pub fn set_log_buffer(&mut self, log_buffer: Arc<LogBuffer>)
Sets the LogBuffer for the UI.
Sourcepub fn update_friends(&mut self, friends: Vec<String>)
pub fn update_friends(&mut self, friends: Vec<String>)
Updates the list of friends in the chat mode’s completer.
Sourcepub fn update_discovered_peers(&mut self, peers: Vec<String>)
pub fn update_discovered_peers(&mut self, peers: Vec<String>)
Updates the list of discovered peers in the chat mode’s completer.
Sourcepub fn preload_messages(&mut self, messages: Vec<Message>)
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- AVecofMessages to preload.
Sourcepub async fn run(&mut self) -> Result<()>
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
impl TerminalUI
Sourcepub(super) async fn handle_event(&mut self, event: UIEvent) -> Result<()>
pub(super) async fn handle_event(&mut self, event: UIEvent) -> Result<()>
Sourceasync fn handle_key_event(&mut self, key: KeyEvent) -> Result<()>
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- TheKeyEventto handle.
§Errors
Returns an error if the current UI mode’s key handler fails.
Source§impl TerminalUI
impl TerminalUI
Sourcepub(super) fn initialize_terminal(&mut self) -> Result<()>
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§impl TerminalUI
impl TerminalUI
Sourcefn render_status_line(
&self,
stdout: &mut impl Write,
row: u16,
width: u16,
) -> Result<()>
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.
Sourcefn render_input_area(
&self,
stdout: &mut impl Write,
row: u16,
width: u16,
height: u16,
) -> Result<()>
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§
Auto Trait Implementations§
impl Freeze for TerminalUI
impl !RefUnwindSafe for TerminalUI
impl Send for TerminalUI
impl Sync for TerminalUI
impl Unpin for TerminalUI
impl !UnwindSafe for TerminalUI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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