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
impl Terminal
Sourcepub fn new(stream: TtyStream) -> Result<Self>
pub fn new(stream: TtyStream) -> Result<Self>
A terminal attached to a program, with DEFAULT_SCROLLBACK lines of scrollback.
Sourcepub fn with_scrollback(stream: TtyStream, max_scrollback: usize) -> Result<Self>
pub fn with_scrollback(stream: TtyStream, max_scrollback: usize) -> Result<Self>
The same, keeping however many lines of scrollback you ask for.
Sourcepub fn with_label(self, label: impl Into<String>) -> Self
pub fn with_label(self, label: impl Into<String>) -> Self
Name this terminal, which is what its “exited” notice ends up saying.
Sourcepub fn with_poll_interval(self, interval: Duration) -> Self
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.
Sourcepub fn request_focus(&mut self)
pub fn request_focus(&mut self)
Take the keyboard on the next frame, the way a click into the grid would.
Sourcepub fn has_exited(&self) -> bool
pub fn has_exited(&self) -> bool
Whether the program behind this terminal has ended.
Sourcepub fn title(&self) -> Option<String>
pub fn title(&self) -> Option<String>
The title the running program set, for a tab strip or a window title.
Sourcepub fn send(&self, bytes: &[u8]) -> Result<()>
pub fn send(&self, bytes: &[u8]) -> Result<()>
Send bytes to the program as if they had been typed.
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
What a copy would put on the clipboard right now.
Sourcepub fn find(&mut self, query: &str, at: usize) -> usize
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.
Sourcepub fn visible_text(&mut self) -> Result<String>
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.
Sourcepub fn drawn_colors(&mut self) -> Result<(Color32, Color32)>
pub fn drawn_colors(&mut self) -> Result<(Color32, Color32)>
The default foreground and background the grid would be painted with right now.
Sourcepub fn set_color_scheme(&mut self, scheme: ColorScheme)
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.
Sourcepub fn poll(&mut self) -> bool
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.
Sourcepub fn ui(&mut self, ui: &mut Ui, style: &TerminalStyle) -> Response
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§
impl !RefUnwindSafe for Terminal
impl !Send for Terminal
impl !Sync for Terminal
impl !UnwindSafe for Terminal
impl Freeze for Terminal
impl Unpin for Terminal
impl UnsafeUnpin for Terminal
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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