pub struct TerminalState { /* private fields */ }Expand description
Terminal state wrapping alacritty_terminal
Implementations§
Source§impl TerminalState
impl TerminalState
Sourcepub fn cwd(&self) -> Option<&Path>
pub fn cwd(&self) -> Option<&Path>
The terminal’s current working directory as last reported by the shell
via OSC 7, if any. Tracks cd within the session (when the shell is
configured to emit OSC 7); None otherwise.
Sourcepub fn drain_pty_write_queue(&self) -> Vec<String>
pub fn drain_pty_write_queue(&self) -> Vec<String>
Drain any pending data that needs to be written back to the PTY.
This is used for responses to terminal queries like DSR (cursor position report). The caller should write this data to the PTY writer.
Sourcepub fn process_output(&mut self, data: &[u8])
pub fn process_output(&mut self, data: &[u8])
Process output from the PTY
Sourcepub fn resize(&mut self, cols: u16, rows: u16)
pub fn resize(&mut self, cols: u16, rows: u16)
Resize the terminal.
Scrollback is streamed to the backing file as complete logical lines. A resize perturbs the visible/history boundary and — on a width change — re-wraps already-persisted content, changing its physical row count. Reconciliation depends on why history changed:
-
Pure height change (no reflow): physical rows are still valid, so leave
synced_history_linesalone. A shrink pushes the top rows into scrollback — new content the next flush writes (no loss). A grow pulls rows back onto the screen; thecurrent <= syncedflush guard suppresses them until genuinely new lines scroll off (no duplicates). -
Width change (reflow): the physical count is meaningless now, but the logical line count is invariant under re-wrapping. Re-derive
synced_history_linesfromsynced_logical_linesby walking the reflowed history (a cheap flag-only scan, no I/O) so the next flush appends exactly the logical lines not yet persisted — width spill included, re-wraps excluded. (Deferred if the alternate screen is up, since the primary grid isn’t the one in view.)
Sourcepub fn mark_clean(&mut self)
pub fn mark_clean(&mut self)
Mark as clean after rendering
Sourcepub fn cursor_position(&self) -> (u16, u16)
pub fn cursor_position(&self) -> (u16, u16)
Get the cursor position (column, row)
Sourcepub fn cursor_visible(&self) -> bool
pub fn cursor_visible(&self) -> bool
Check if cursor is visible
Sourcepub fn last_visible_line(&self) -> String
pub fn last_visible_line(&self) -> String
Snapshot of the cursor row’s text content as a plain string.
Used by the terminal_output plugin hook so listeners (e.g.
the Orchestrator agent state machine) can match prompt patterns
without a separate readback API. Returns cells [0..cursor_col)
of the cursor row so a legitimate trailing space typed by the
program (typical for prompts like "... (Y/n): ") is
preserved while the unwritten right-edge padding past the
cursor is dropped. Falls back to trimming the whole row when
the cursor has wrapped to the start of a freshly-allocated
next row (col == 0): the visible content lives one row up,
and the trailing space ambiguity doesn’t apply (a wrap means
the line was full).
Sourcepub fn get_line(&self, row: u16) -> Vec<TerminalCell>
pub fn get_line(&self, row: u16) -> Vec<TerminalCell>
Get a line of content for rendering
Returns cells as (char, foreground_color, background_color, flags) tuples. Colors are ANSI color indices (0-255) or None for default. Accounts for scroll offset (display_offset) when accessing lines.
Sourcepub fn content_string(&self) -> String
pub fn content_string(&self) -> String
Get all visible content as a string (for testing/debugging)
Sourcepub fn full_content_string(&self) -> String
pub fn full_content_string(&self) -> String
Get all content including scrollback history as a string Lines are in chronological order (oldest first)
WARNING: This is O(total_history) and should NOT be used in hot paths. For mode switching, use the incremental streaming architecture instead:
flush_new_scrollback()during PTY readsappend_visible_screen()on mode exit
Sourcepub fn history_size(&self) -> usize
pub fn history_size(&self) -> usize
Get the number of scrollback history lines
Sourcepub fn set_title(&mut self, title: String)
pub fn set_title(&mut self, title: String)
Set the terminal title (called when escape sequence is received)
Sourcepub fn scroll_to_bottom(&mut self)
pub fn scroll_to_bottom(&mut self)
Scroll to the bottom of the terminal (display offset = 0) Used when re-entering terminal mode from scrollback view
Sourcepub fn is_alternate_screen(&self) -> bool
pub fn is_alternate_screen(&self) -> bool
Check if the terminal is in alternate screen mode. Programs like vim, less, htop use alternate screen.
Sourcepub fn wants_mouse_events(&self) -> bool
pub fn wants_mouse_events(&self) -> bool
Check if the terminal wants mouse events reported. Returns true if any mouse reporting mode is enabled.
Sourcepub fn uses_sgr_mouse(&self) -> bool
pub fn uses_sgr_mouse(&self) -> bool
Check if SGR mouse encoding is enabled (modern mouse protocol).
Sourcepub fn uses_alternate_scroll(&self) -> bool
pub fn uses_alternate_scroll(&self) -> bool
Check if alternate scroll mode is enabled. When enabled, scroll wheel should be sent as up/down arrow keys.
Sourcepub fn is_app_cursor(&self) -> bool
pub fn is_app_cursor(&self) -> bool
Check if application cursor keys mode (DECCKM) is enabled.
Programs like less, git log set this mode so that arrow keys
send \x1bOA (SS3) instead of \x1b[A (CSI).
Sourcepub fn flush_new_scrollback<W: Write>(
&mut self,
writer: &mut W,
) -> Result<usize>
pub fn flush_new_scrollback<W: Write>( &mut self, writer: &mut W, ) -> Result<usize>
Flush newly scrolled-off scrollback to the writer as complete logical lines, returning the number of logical lines written.
Call after process_output() (and before reading the backing file) to
incrementally persist scrollback. Rows that alacritty wrapped (WRAPLINE)
are joined into one unwrapped logical line, so the backing file stores
logical lines — the editor then soft-wraps them to whatever width the
scroll-back view happens to be, instead of being frozen at the width they
were captured. Only logical lines that have fully scrolled into history
are written; a trailing line still continuing into the visible screen is
left for a later flush, keeping the file on a logical-line boundary.
Sourcepub fn append_visible_screen<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn append_visible_screen<W: Write>(&self, writer: &mut W) -> Result<()>
Append the visible screen content to the writer as logical lines.
Call this when exiting terminal mode (or saving a session) to add the
current screen to the backing file. Wrapped rows are joined like
flush_new_scrollback, but every visible row is emitted (including the
trailing logical line and blank rows) so the scroll-back viewport can
anchor to the start of this block and line up with the live PTY frame.
The block is temporary — re-entering terminal mode truncates the file
back to backing_file_history_end.
Sourcepub fn backing_file_history_end(&self) -> u64
pub fn backing_file_history_end(&self) -> u64
Get the byte offset where scrollback history ends in the backing file.
Used for truncating the file when re-entering terminal mode (to remove the visible screen portion).
Sourcepub fn set_backing_file_history_end(&mut self, offset: u64)
pub fn set_backing_file_history_end(&mut self, offset: u64)
Set the byte offset where scrollback history ends.
Call this after flushing scrollback to record the file position.
Sourcepub fn synced_history_lines(&self) -> usize
pub fn synced_history_lines(&self) -> usize
Get the number of scrollback lines that have been synced to the backing file.
Sourcepub fn reset_sync_state(&mut self)
pub fn reset_sync_state(&mut self)
Reset sync state (e.g., when starting fresh or after truncation).
Auto Trait Implementations§
impl Freeze for TerminalState
impl RefUnwindSafe for TerminalState
impl Send for TerminalState
impl Sync for TerminalState
impl Unpin for TerminalState
impl UnsafeUnpin for TerminalState
impl UnwindSafe for TerminalState
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more