Skip to main content

TUI

Struct TUI 

Source
pub struct TUI { /* private fields */ }
Expand description

Top-level TUI manager.

Owns the terminal, a list of mounted components, overlays, and a Renderer that performs differential drawing. Only one component receives focus at a time; it is the sole recipient of input events.

§Example

use photon_ui::{
    TUI,
    TestTerminal,
    components::Text,
};

let mut tui = TUI::new(Box::new(TestTerminal::new(80, 24)));
tui.mount(Box::new(Text::new("Hello", 0, 0)));
tui.render_frame().unwrap();

Implementations§

Source§

impl TUI

Source

pub fn new(terminal: Box<dyn Terminal>) -> Self

Create a new TUI backed by the given terminal.

Source

pub fn terminal(&self) -> &dyn Terminal

Borrow the underlying terminal.

Source

pub fn mount(&mut self, component: Box<dyn Component>)

Add a component to the TUI.

The component is appended to the children list. If no component currently has focus, the new component receives focus automatically.

Source

pub fn set_focus(&mut self, index: usize)

Move focus to the component at index.

The previously focused component, if any, is unfocused first.

Source

pub fn clear_children(&mut self)

Remove all children and reset focus.

Source

pub fn add_overlay(&mut self, overlay: Overlay)

Add an overlay on top of the main UI.

Source

pub fn clear_overlays(&mut self)

Remove all overlays.

Source

pub fn show_modal(&mut self, modal: Box<dyn Component>)

Show a modal dialog on top of the main UI.

The modal captures all input until it is dismissed. Focus is moved to the modal content automatically. When dismissed, focus returns to the previously focused component.

Source

pub fn dismiss_modal(&mut self)

Dismiss the currently open modal, restoring previous focus.

Source

pub fn modal_active(&self) -> bool

Returns true if a modal is currently open.

Source

pub fn set_layout(&mut self, layout: Layout)

Set a layout for splitting the terminal area among children.

Source

pub fn clear_layout(&mut self)

Clear the layout, reverting to vertical stacking.

Source

pub fn reset(&mut self)

Reset the TUI for a fresh page / screen.

Clears all children, overlays, and layout, and schedules a full screen redraw so no stale content or ANSI attributes bleed through.

Source

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

Restore the terminal (leave alternate screen, disable raw mode, show cursor).

Source

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

Render one frame to the terminal.

  1. Queries terminal size.
  2. Decides RenderStrategy (first render, full redraw on resize, or diff).
  3. Renders all children and overlays into a composite screen buffer.
  4. Deletes stale terminal images.
  5. Writes the result through the Renderer.
  6. Positions the hardware cursor.
Source

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

Dispatch an event to the focused component, falling back to other children if the focused one returns crate::InputResult::Ignored.

Also handles Tab to cycle focus between focusable children.

Auto Trait Implementations§

§

impl !RefUnwindSafe for TUI

§

impl !Send for TUI

§

impl !Sync for TUI

§

impl !UnwindSafe for TUI

§

impl Freeze for TUI

§

impl Unpin for TUI

§

impl UnsafeUnpin for TUI

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