Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor {
    pub row: u16,
    pub col: u16,
    pub visible: bool,
    pub pending_wrap: bool,
    pub attrs: SgrAttrs,
    pub charset_slots: [u8; 4],
    pub active_charset: u8,
    pub single_shift: Option<u8>,
    /* private fields */
}
Expand description

Terminal cursor state.

Fields§

§row: u16

Current row (0-indexed from top of viewport).

§col: u16

Current column (0-indexed from left).

§visible: bool

Whether the cursor is visible (DECTCEM).

§pending_wrap: bool

Pending wrap: the cursor is at the right margin and the next printable character should trigger a line wrap. This avoids the xterm off-by-one behavior where the cursor sits past the last column.

§attrs: SgrAttrs

Current SGR attributes applied to newly written characters.

§charset_slots: [u8; 4]

Character set slots G0–G3. Each stores a charset designator byte: b'B' = ASCII (default), b'0' = DEC Special Graphics, b'A' = UK.

§active_charset: u8

Active character set slot index (0 = G0, default).

§single_shift: Option<u8>

Single-shift override: if Some(2) or Some(3), the next printed char uses G2 or G3 respectively, then clears back to None.

Implementations§

Source§

impl Cursor

Source

pub fn new(cols: u16, rows: u16) -> Self

Create a cursor for a grid of the given dimensions.

Source

pub fn at(row: u16, col: u16) -> Self

Create a cursor at the given position with default attributes.

Source

pub fn scroll_top(&self) -> u16

Top of scroll region (inclusive).

Source

pub fn scroll_bottom(&self) -> u16

Bottom of scroll region (exclusive).

Source

pub fn set_scroll_region(&mut self, top: u16, bottom: u16, rows: u16)

Set scroll region margins (DECSTBM). Both are 0-indexed. top is inclusive, bottom is exclusive.

If top >= bottom or bottom > rows, the request is ignored.

Source

pub fn reset_scroll_region(&mut self, rows: u16)

Reset scroll region to full screen.

Source

pub fn in_scroll_region(&self) -> bool

Whether the cursor is inside the scroll region.

Source

pub fn clamp(&mut self, rows: u16, cols: u16)

Clamp the cursor position to the given grid bounds.

Source

pub fn move_to(&mut self, row: u16, col: u16, rows: u16, cols: u16)

CUP: Move cursor to absolute position (0-indexed). Coordinates are clamped to grid bounds.

Source

pub fn move_up(&mut self, count: u16)

CUU: Move cursor up by count rows, stopping at the top margin.

Source

pub fn move_down(&mut self, count: u16, rows: u16)

CUD: Move cursor down by count rows, stopping at the bottom margin.

Source

pub fn move_right(&mut self, count: u16, cols: u16)

CUF: Move cursor right by count columns, stopping at the right margin.

Source

pub fn move_left(&mut self, count: u16)

CUB: Move cursor left by count columns, stopping at column 0.

Source

pub fn carriage_return(&mut self)

CR: Carriage return — move cursor to column 0.

Source

pub fn next_tab_stop(&self, cols: u16) -> u16

Advance to the next tab stop. Returns the new column.

Source

pub fn prev_tab_stop(&self) -> u16

Move back to the previous tab stop. Returns the new column.

Source

pub fn set_tab_stop(&mut self)

Set a tab stop at the current column.

Source

pub fn clear_tab_stop(&mut self)

Clear the tab stop at the current column.

Source

pub fn clear_all_tab_stops(&mut self)

Clear all tab stops.

Source

pub fn reset_tab_stops(&mut self, cols: u16)

Reset tab stops to the default interval (every 8 columns).

Source

pub fn resize(&mut self, new_cols: u16, new_rows: u16)

Adjust cursor state after a grid resize.

Source§

impl Cursor

Source

pub fn effective_charset(&self) -> u8

Get the effective charset designator for the next printed character, accounting for single-shift overrides.

Source

pub fn consume_single_shift(&mut self)

Consume the single-shift state (call after printing a character).

Source

pub fn designate_charset(&mut self, slot: u8, charset: u8)

Designate a charset for a slot.

Source

pub fn reset_charset(&mut self)

Reset charset state to defaults (all ASCII, G0 active, no single-shift).

Trait Implementations§

Source§

impl Clone for Cursor

Source§

fn clone(&self) -> Cursor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cursor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Cursor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Cursor

Source§

fn eq(&self, other: &Cursor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Cursor

Source§

impl StructuralPartialEq for Cursor

Auto Trait Implementations§

§

impl Freeze for Cursor

§

impl RefUnwindSafe for Cursor

§

impl Send for Cursor

§

impl Sync for Cursor

§

impl Unpin for Cursor

§

impl UnwindSafe for Cursor

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.