Struct Interface

Source
pub struct Interface<'a> { /* private fields */ }
Expand description

A TTY-based user-interface providing optimized update rendering.

Implementations§

Source§

impl Interface<'_>

Source

pub fn new_alternate<'a>(device: &'a mut dyn Device) -> Result<Interface<'a>>

Create a new interface for the specified device on the alternate screen.

§Examples
use tty_interface::Interface;

let interface = Interface::new_alternate(&mut device)?;
Source

pub fn new_relative<'a>(device: &'a mut dyn Device) -> Result<Interface<'a>>

Create a new interface for the specified device which renders relatively in the buffer.

§Examples
use tty_interface::Interface;

let interface = Interface::new_relative(&mut device)?;
Source

pub fn exit(self) -> Result<()>

When finished using this interface, uninitialize its terminal configuration.

§Examples
use tty_interface::Interface;

let interface = Interface::new_alternate(&mut device)?;
interface.exit()?;
Source

pub fn set(&mut self, position: Position, text: &str)

Update the interface’s text at the specified position. Changes are staged until applied.

§Examples
use tty_interface::{Interface, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;
interface.set(pos!(1, 1), "Hello, world!");
Source

pub fn set_styled(&mut self, position: Position, text: &str, style: Style)

Update the interface’s text at the specified position. Changes are staged until applied.

§Examples
use tty_interface::{Interface, Style, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;
interface.set_styled(pos!(1, 1), "Hello, world!", Style::new().set_bold(true));
Source

pub fn clear_line(&mut self, line: u16)

Clear all text on the specified line. Changes are staged until applied.

§Examples
use tty_interface::{Interface, Style, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;

// Write "Hello," and "world!" on two different lines
interface.set(pos!(0, 0), "Hello,");
interface.set(pos!(0, 1), "world!");
interface.apply()?;

// Clear the second line, "world!"
interface.clear_line(1);
interface.apply()?;
Source

pub fn clear_rest_of_line(&mut self, from: Position)

Clear the remainder of the line from the specified position. Changes are staged until applied.

§Examples
use tty_interface::{Interface, Style, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;

// Write "Hello, world!" to the first line
interface.set(pos!(0, 0), "Hello, world!");
interface.apply()?;

// Clear everything after "Hello"
interface.clear_rest_of_line(pos!(5, 0));
interface.apply()?;
Source

pub fn clear_rest_of_interface(&mut self, from: Position)

Clear the remainder of the interface from the specified position. Changes are staged until applied.

§Examples
use tty_interface::{Interface, Style, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;

// Write two lines of content
interface.set(pos!(0, 0), "Hello, world!");
interface.set(pos!(0, 1), "Another line");
interface.apply()?;

// Clear everything after "Hello", including the second line
interface.clear_rest_of_interface(pos!(5, 0));
interface.apply()?;
Source

pub fn set_cursor(&mut self, position: Option<Position>)

Update the interface’s cursor to the specified position, or hide it if unspecified.

§Examples
use tty_interface::{Interface, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;
interface.set_cursor(Some(pos!(1, 2)));
Source

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

Applies staged changes to the terminal.

§Examples
use tty_interface::{Interface, Position, pos};

let mut interface = Interface::new_alternate(&mut device)?;
interface.set(pos!(1, 1), "Hello, world!");
interface.apply()?;

Auto Trait Implementations§

§

impl<'a> Freeze for Interface<'a>

§

impl<'a> !RefUnwindSafe for Interface<'a>

§

impl<'a> !Send for Interface<'a>

§

impl<'a> !Sync for Interface<'a>

§

impl<'a> Unpin for Interface<'a>

§

impl<'a> !UnwindSafe for Interface<'a>

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.