Skip to main content

TerminalState

Struct TerminalState 

Source
#[non_exhaustive]
pub struct TerminalState { /* private fields */ }
Expand description

A terminal: the latest frame, the program’s status and everything the element needs to draw and to send input.

Implementations§

Source§

impl TerminalState

Source

pub fn marked_text(&self) -> Option<&str>

Text being composed by an input method, drawn at the cursor.

Source§

impl TerminalState

Source

pub fn new( source: impl FrameSource, config: TerminalConfig, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

A terminal fed by source, started at once.

Source

pub fn local( options: LocalTerminalOptions, config: TerminalConfig, window: &mut Window, cx: &mut Context<'_, Self>, ) -> Self

A terminal running a local program in a pty.

Source

pub fn apply(&mut self, snapshot: &TerminalSnapshot, cx: &mut Context<'_, Self>)

Install a snapshot. Public so a host driving its own frames can use the same path as the engine.

Source

pub fn frame(&self) -> &Arc<TerminalFrame> ⓘ

The frame being drawn.

Source

pub fn status(&self) -> &TerminalStatus

The program’s status.

Source

pub fn title(&self) -> &SharedString

The title the program set.

Source

pub fn cwd(&self) -> Option<&Path>

The working directory: the one the shell reported through its integration (OSC 7), or else the foreground process’s.

Source

pub fn foreground(&self) -> Option<&ForegroundProcess>

The process in the foreground, such as the shell at its prompt or an editor it started, when the source reports one. A local pty does. TerminalEvent::ForegroundChanged reports a change.

Source

pub fn needs_confirm_close(&self) -> bool

Whether closing the terminal would end a program other than the one it started, such as an editor or a build in the foreground, so an application should ask first, as Ghostty does. Without a foreground process, as from a stream, it is whether the cursor is away from a shell prompt.

Source

pub fn input_backlog(&self) -> usize

Queued input bytes not yet delivered; the busy signal.

Source

pub fn appearance(&self) -> &TerminalAppearance

The appearance.

Source

pub fn font_size(&self, cx: &App) -> Pixels

The font size the grid draws with: the zoomed size, else the appearance’s, else the theme’s code font size.

Source

pub fn set_font_size( &mut self, size: impl Into<Pixels>, cx: &mut Context<'_, Self>, )

Draw the grid at size, clamped to 1-255 points as Ghostty clamps it. The grid is measured again at the next paint, which resizes the program’s grid to fit. Emits TerminalEvent::FontSizeChanged.

Source

pub fn increase_font_size( &mut self, points: impl Into<Pixels>, cx: &mut Context<'_, Self>, )

Zoom the font in by points, as Ghostty’s increase_font_size.

Source

pub fn decrease_font_size( &mut self, points: impl Into<Pixels>, cx: &mut Context<'_, Self>, )

Zoom the font out by points, as Ghostty’s decrease_font_size.

Source

pub fn reset_font_size(&mut self, cx: &mut Context<'_, Self>)

Go back to the appearance’s font size, or the theme’s.

Source

pub fn set_appearance( &mut self, appearance: TerminalAppearance, cx: &mut Context<'_, Self>, )

Change the appearance. The grid is measured again at the next paint.

Source

pub fn colors(&self) -> &TerminalColors

The colors.

Source

pub fn set_colors(&mut self, colors: TerminalColors, cx: &mut Context<'_, Self>)

Change the colors. The next frame carries them.

Source

pub fn is_live(&self) -> bool

Whether a program is running.

Source

pub fn is_closed(&self) -> bool

Whether the terminal was closed.

Source

pub fn is_visible(&self) -> bool

Whether the terminal is visible.

Source

pub fn set_visible(&mut self, visible: bool, cx: &mut Context<'_, Self>)

Hidden terminals keep parsing output but stop producing frames and stop the cursor cadence. Revealing one asks for a current frame.

Source

pub fn close(&mut self, cx: &mut Context<'_, Self>)

Stop the program and the source. Idempotent.

Source

pub fn set_right_click_passthrough(&mut self, passthrough: bool)

Whether a right click goes to a program that reports the mouse. It does by default. When it does not, or a modifier is held, or no program reports the mouse, the click is left to the host, such as for a context menu.

Source

pub fn has_selection(&self) -> bool

Whether a non-empty selection exists.

Source

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

The selected text as shown, without scrollback.

The link under the pointer while the platform modifier is held.

Source

pub fn copy(&mut self, cx: &mut Context<'_, Self>)

Copy the selection to the clipboard. A live engine is asked for the text because it can reach scrollback the frame does not carry.

Source

pub fn select_all(&mut self, cx: &mut Context<'_, Self>)

Select the whole viewport.

Source

pub fn clear_selection(&mut self, cx: &mut Context<'_, Self>) -> bool

Drop the selection. Returns whether there was one.

Source

pub fn clear(&mut self, cx: &mut Context<'_, Self>)

Send form feed, which clears the screen at most shells.

Source

pub fn paste(&mut self, cx: &mut Context<'_, Self>)

Paste the clipboard text.

Source

pub fn paste_text( &mut self, text: impl Into<String>, cx: &mut Context<'_, Self>, )

Paste text, bracketed when the program asked for it.

Source

pub fn send_text(&mut self, text: impl Into<String>, cx: &mut Context<'_, Self>)

Send raw text to the program.

Source

pub fn scroll(&mut self, request: ScrollRequest, cx: &mut Context<'_, Self>)

Scroll the viewport.

Source

pub fn scroll_pages(&mut self, pages: isize, cx: &mut Context<'_, Self>)

Scroll by whole pages; negative is toward older output.

Source

pub fn is_scrolled(&self) -> bool

Whether the viewport is scrolled into history.

Source

pub fn focus_handle(&self) -> &FocusHandle

The focus handle.

Trait Implementations§

Source§

impl EntityInputHandler for TerminalState

Source§

fn bounds_for_range( &mut self, _range_utf16: Range<usize>, element_bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>

The candidate window follows the cursor cell.

Source§

fn text_for_range( &mut self, range: Range<usize>, adjusted: &mut Option<Range<usize>>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<String>

Source§

fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>

Source§

fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)

Source§

fn replace_text_in_range( &mut self, _range: Option<Range<usize>>, text: &str, _window: &mut Window, cx: &mut Context<'_, Self>, )

Source§

fn replace_and_mark_text_in_range( &mut self, _range: Option<Range<usize>>, new_text: &str, _new_selected_range: Option<Range<usize>>, _window: &mut Window, cx: &mut Context<'_, Self>, )

Source§

fn character_index_for_point( &mut self, _point: Point<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>

Source§

fn paste( &mut self, item: ClipboardItem, window: &mut Window, cx: &mut Context<'_, Self>, )

See InputHandler::paste for details
Source§

fn selection_bounds_for_range( &mut self, _range_utf16: Range<usize>, _element_bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Vec<Bounds<Pixels>>

Source§

fn set_selected_text_range( &mut self, _range_utf16: Range<usize>, _window: &mut Window, _cx: &mut Context<'_, Self>, )

Source§

fn text_length_utf16( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>

Source§

fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool

Source§

fn text_input_configuration( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> TextInputConfiguration

Source§

fn text_input_editable_range( &mut self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

impl EventEmitter<TerminalEvent> for TerminalState

Source§

impl Focusable for TerminalState

Source§

fn focus_handle(&self, _: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl Render for TerminalState

Source§

fn render( &mut self, _: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more