pub struct VirtualTerminal { /* private fields */ }Expand description
In-memory virtual terminal with cursor tracking and ANSI interpretation.
§Example
use ftui_pty::virtual_terminal::VirtualTerminal;
let mut vt = VirtualTerminal::new(80, 24);
vt.feed(b"Hello, World!");
assert_eq!(vt.char_at(0, 0), Some('H'));
assert_eq!(vt.char_at(12, 0), Some('!'));
assert_eq!(vt.cursor(), (13, 0));Implementations§
Source§impl VirtualTerminal
impl VirtualTerminal
Sourcepub fn with_quirks(width: u16, height: u16, quirks: QuirkSet) -> Self
pub fn with_quirks(width: u16, height: u16, quirks: QuirkSet) -> Self
Sourcepub const fn cursor_visible(&self) -> bool
pub const fn cursor_visible(&self) -> bool
Whether the cursor is currently visible.
Sourcepub const fn is_alternate_screen(&self) -> bool
pub const fn is_alternate_screen(&self) -> bool
Whether alternate screen mode is active.
Sourcepub fn set_quirks(&mut self, quirks: QuirkSet)
pub fn set_quirks(&mut self, quirks: QuirkSet)
Override the active quirk set.
Sourcepub fn scrollback_len(&self) -> usize
pub fn scrollback_len(&self) -> usize
Number of lines in the scrollback buffer.
Sourcepub fn set_max_scrollback(&mut self, max: usize)
pub fn set_max_scrollback(&mut self, max: usize)
Set the maximum scrollback lines.
Sourcepub fn char_at(&self, x: u16, y: u16) -> Option<char>
pub fn char_at(&self, x: u16, y: u16) -> Option<char>
Get the character at (x, y). Returns None if out of bounds.
Sourcepub fn style_at(&self, x: u16, y: u16) -> Option<&CellStyle>
pub fn style_at(&self, x: u16, y: u16) -> Option<&CellStyle>
Get the style at (x, y). Returns None if out of bounds.
Sourcepub fn cell_at(&self, x: u16, y: u16) -> Option<&VCell>
pub fn cell_at(&self, x: u16, y: u16) -> Option<&VCell>
Get a reference to the cell at (x, y). Returns None if out of bounds.
Sourcepub fn row_text(&self, y: u16) -> String
pub fn row_text(&self, y: u16) -> String
Get the text content of a row (trailing spaces trimmed).
Sourcepub fn screen_text(&self) -> String
pub fn screen_text(&self) -> String
Get all visible text as a string (rows separated by newlines).
Sourcepub fn scrollback_line(&self, idx: usize) -> Option<String>
pub fn scrollback_line(&self, idx: usize) -> Option<String>
Get a scrollback line by index (0 = oldest).
Sourcepub fn put_str(&mut self, s: &str)
pub fn put_str(&mut self, s: &str)
Write a plain-text string to the terminal.
Each character is fed through put_char, which
handles auto-wrap, wide characters, insert mode, and charset
translation — but no ANSI escape sequences are interpreted.
Use this when you have pre-sanitized text and want deterministic
character-level output.
§Example
use ftui_pty::virtual_terminal::VirtualTerminal;
let mut vt = VirtualTerminal::new(10, 1);
vt.put_str("Hello");
assert_eq!(vt.row_text(0), "Hello");
assert_eq!(vt.cursor(), (5, 0));Sourcepub fn set_cursor_position(&mut self, x: u16, y: u16)
pub fn set_cursor_position(&mut self, x: u16, y: u16)
Move the cursor to an absolute position, clamped to terminal bounds.
Coordinates are 0-indexed. Out-of-range values are clamped:
x to width - 1, y to height - 1.
§Example
use ftui_pty::virtual_terminal::VirtualTerminal;
let mut vt = VirtualTerminal::new(80, 24);
vt.set_cursor_position(5, 10);
assert_eq!(vt.cursor(), (5, 10));
// Out-of-range values are clamped.
vt.set_cursor_position(999, 999);
assert_eq!(vt.cursor(), (79, 23));Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the entire visible display, filling every cell with the current style’s background.
This is the programmatic equivalent of ESC[2J. The cursor
position is not changed. Scrollback is not affected — use
clear_scrollback for that.
§Example
use ftui_pty::virtual_terminal::VirtualTerminal;
let mut vt = VirtualTerminal::new(5, 1);
vt.put_str("Hello");
vt.clear();
assert_eq!(vt.row_text(0), "");Sourcepub fn clear_scrollback(&mut self)
pub fn clear_scrollback(&mut self)
Clear the scrollback buffer.
This removes all lines that have scrolled off the visible area. The visible display is not affected.
Sourcepub fn cpr_response(&self) -> Vec<u8> ⓘ
pub fn cpr_response(&self) -> Vec<u8> ⓘ
Generate a cursor position report (CPR) response.
Format: ESC [ Py ; Px R (1-indexed).
Sourcepub fn da1_response(&self) -> Vec<u8> ⓘ
pub fn da1_response(&self) -> Vec<u8> ⓘ
Generate a device attributes (DA1) response. Reports as a VT220 with ANSI color.
Sourcepub fn put_char(&mut self, ch: char)
pub fn put_char(&mut self, ch: char)
Place a single character at the current cursor position, applying all terminal output logic: charset translation, Unicode width detection, auto-wrap (DECAWM), wide-character handling, insert mode (IRM), and cursor advancement.
This is the character-level entry point that feed and
feed_str use internally after ANSI/UTF-8 parsing.
Call it directly when you already have decoded characters and want the
terminal to handle wrapping, widths, and cursor movement.
Zero-width characters (combining marks, ZWJ) are silently skipped.
§Example
use ftui_pty::virtual_terminal::VirtualTerminal;
let mut vt = VirtualTerminal::new(10, 3);
vt.put_char('H');
vt.put_char('i');
assert_eq!(vt.row_text(0), "Hi");
assert_eq!(vt.cursor(), (2, 0));Auto Trait Implementations§
impl Freeze for VirtualTerminal
impl RefUnwindSafe for VirtualTerminal
impl Send for VirtualTerminal
impl Sync for VirtualTerminal
impl Unpin for VirtualTerminal
impl UnsafeUnpin for VirtualTerminal
impl UnwindSafe for VirtualTerminal
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.