Skip to main content

Terminal

Struct Terminal 

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

A terminal: an emulator, the program attached to it, and the grid both end up drawn as.

Bytes the program writes are read from the TtyStream it was built with, on whichever thread draws the widget. The emulator is !Send, so the terminal lives on that thread for good — which is where a UI wants it anyway.

let mut terminal = egui_tty::Terminal::new(stream)?;
let style = egui_tty::TerminalStyle::from_visuals(ui.visuals());
terminal.ui(ui, &style);

Implementations§

Source§

impl Terminal

Source

pub fn new(stream: TtyStream) -> Result<Self>

A terminal attached to a program, with DEFAULT_SCROLLBACK lines of scrollback.

Source

pub fn with_scrollback(stream: TtyStream, max_scrollback: usize) -> Result<Self>

The same, keeping however many lines of scrollback you ask for.

Source

pub fn with_label(self, label: impl Into<String>) -> Self

Name this terminal, which is what its “exited” notice ends up saying.

Source

pub fn with_poll_interval(self, interval: Duration) -> Self

How often a terminal with a live program asks to be drawn again. The default is 33ms, which is fast enough to feel immediate and slow enough to leave the CPU alone.

Source

pub fn request_focus(&mut self)

Take the keyboard on the next frame, the way a click into the grid would.

Source

pub fn has_exited(&self) -> bool

Whether the program behind this terminal has ended.

Source

pub fn size(&self) -> (u16, u16)

The size of the grid the program is talking to, in cells.

Source

pub fn title(&self) -> Option<String>

The title the running program set, for a tab strip or a window title.

Source

pub fn send(&self, bytes: &[u8]) -> Result<()>

Send bytes to the program as if they had been typed.

Source

pub fn selected_text(&self) -> Option<String>

What a copy would put on the clipboard right now.

Source

pub fn find(&mut self, query: &str, at: usize) -> usize

Search the screen and the scrollback, show the atth match, and say how many there were.

Call this when a query or the current match changes rather than every frame: it reads the whole scrollback back as text.

Source

pub fn visible_text(&mut self) -> Result<String>

Everything on screen, one line per row and trailing blanks trimmed.

This reads the emulator’s own grid, which is what the widget paints from, so it is how a test checks that a program’s output made it through the VT parser.

Source

pub fn drawn_colors(&mut self) -> Result<(Color32, Color32)>

The default foreground and background the grid would be painted with right now.

Source

pub fn set_color_scheme(&mut self, scheme: ColorScheme)

Put a scheme’s colors on the emulator. Drawing does this for you; call it directly to set the colors of a terminal that is not on screen yet.

Source

pub fn poll(&mut self) -> bool

Feed everything the program has written since the last call into the emulator, without drawing. Returns whether anything arrived.

Drawing does this first, so a UI never has to; a test that waits on output does.

Source

pub fn ui(&mut self, ui: &mut Ui, style: &TerminalStyle) -> Response

Draw the terminal into all the space the ui has left, and handle its input.

While the program is alive the widget asks for the next frame itself, so output that arrives with nothing else going on still appears — see with_poll_interval.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.