[][src]Struct unsegen::base::cursor::CursorRestorer

#[must_use]pub struct CursorRestorer<'a, 'c: 'a, 'g: 'c, T: 'c + CursorTarget> { /* fields omitted */ }

Guard value used to restore desired state to a cursor at the end of the scope. Created using Cursor::save.

Implementations

impl<'a, 'c: 'a, 'g: 'c, T: 'c + CursorTarget> CursorRestorer<'a, 'c, 'g, T>[src]

pub fn style_modifier(self) -> Self[src]

Save the current style modifier of the underlying cursor and restore it when this struct is dropped.

pub fn line_start_column(self) -> Self[src]

Save the current line start column of the underlying cursor and restore it when this struct is dropped.

pub fn col(self) -> Self[src]

Save the current column position of the underlying cursor and restore it when this struct is dropped.

pub fn row(self) -> Self[src]

Save the current row position of the underlying cursor and restore it when this struct is dropped.

Methods from Deref<Target = Cursor<'c, 'g, T>>

pub fn get_position(&self) -> (ColIndex, RowIndex)[src]

pub fn get_col(&self) -> ColIndex[src]

pub fn get_row(&self) -> RowIndex[src]

pub fn move_by(&mut self, x: ColDiff, y: RowDiff)[src]

Move the cursor by the specifed amount in x- and y-direction.

Examples:

use unsegen::base::*;

let mut w = ExtentEstimationWindow::with_width(Width::new(20).unwrap());
let mut cursor = Cursor::new(&mut w).position(ColIndex::new(27), RowIndex::new(37));

cursor.move_by(ColDiff::new(10), RowDiff::new(-10));

assert_eq!(cursor.get_col(), ColIndex::new(37));
assert_eq!(cursor.get_row(), RowIndex::new(27));

pub fn move_to(&mut self, x: ColIndex, y: RowIndex)[src]

pub fn move_to_x(&mut self, x: ColIndex)[src]

pub fn move_to_y(&mut self, y: RowIndex)[src]

pub fn move_left(&mut self)[src]

Move left, but skip empty clusters, also wrap to the line above if wrapping is active

pub fn move_right(&mut self)[src]

Move right, but skip empty clusters, also wrap to the line below if wrapping is active

pub fn set_wrapping_mode(&mut self, wm: WrappingMode)[src]

pub fn set_line_start_column(&mut self, column: ColIndex)[src]

pub fn move_line_start_column(&mut self, d: ColDiff)[src]

Move the start column by the specified amount.

pub fn set_style_modifier(&mut self, style_modifier: StyleModifier)[src]

pub fn get_style_modifier(&mut self) -> StyleModifier[src]

pub fn apply_style_modifier(&mut self, style_modifier: StyleModifier)[src]

Apply the specified modifier on_top of the current modifier.

pub fn set_tab_column_width(&mut self, width: Width)[src]

Set how far a tab character ('\t') will move the cursor to the right.

pub fn backspace(&mut self)[src]

Emulate a "backspace" action, i.e., move the cursor one character to the left and replace the character under the cursor with a space.

pub fn clear_line_left(&mut self)[src]

Clear all character to the left of the cursor in the current line including the cursor position itself.

pub fn clear_line_right(&mut self)[src]

Clear all character to the right of the cursor in the current line including the cursor position itself.

pub fn clear_line(&mut self)[src]

Clear all characters in the current line.

pub fn fill_and_wrap_line(&mut self)[src]

Fill the remainder of the line with spaces and wrap to the beginning of the next line.

pub fn wrap_line(&mut self)[src]

Wrap to the beginning of the current line.

pub fn carriage_return(&mut self)[src]

Move the cursor to the beginning of the current line (but do not change the row position).

pub fn num_expected_wraps(&self, line: &str) -> usize[src]

Calculate the number of wraps that are expected when writing the given text to the terminal, but do not write the text itself.

pub fn get_current_cell_mut(&mut self) -> Option<&mut StyledGraphemeCluster>[src]

(Mutably) get the cell under the current cursor position.

pub fn get_current_cell(&self) -> Option<&StyledGraphemeCluster>[src]

Get the cell under the current cursor position.

pub fn write_preformatted(&mut self, clusters: &[StyledGraphemeCluster])[src]

Write a preformatted slice of styled grapheme clusters to the target at the current cursor position.

Be very careful when using this function. Although safety is guaranteed, the program can easily panic when using this function in any wrong way.

A safe way to obtain a valid argument for this function would be to implement a CursorTarget with a Vec as a backing store and write to that target using a cursor. Any slice whose endpoints are defined by cursor positions which occured while writing to this target is valid.

Panics

Panics if the number of clusters does not equals its total width

pub fn write(&mut self, text: &str)[src]

Write a string to the target at the current cursor position.

pub fn writeln(&mut self, text: &str)[src]

pub fn save<'a>(&'a mut self) -> CursorRestorer<'a, 'c, 'g, T>[src]

Save the current state of the cursor. The current state will be restored when the returned CursorRestorer is dropped.

Examples:

use unsegen::base::*;

let mut w = ExtentEstimationWindow::with_width(Width::new(20).unwrap());
let mut cursor = Cursor::new(&mut w)
    .position(ColIndex::new(0), RowIndex::new(0));

let old_style = cursor.get_style_modifier();
{
    let mut cursor = cursor.save().col().style_modifier();
    cursor.apply_style_modifier(StyleModifier::new().bold(BoolModifyMode::Toggle));
    cursor.write("testing, testing, oioioi!");
}
assert_eq!(cursor.get_col(), ColIndex::new(0));
assert_eq!(cursor.get_style_modifier(), old_style);

Trait Implementations

impl<'a, 'c: 'a, 'g: 'c, T: 'c + CursorTarget> Deref for CursorRestorer<'a, 'c, 'g, T>[src]

type Target = Cursor<'c, 'g, T>

The resulting type after dereferencing.

impl<'a, 'c: 'a, 'g: 'c, T: 'c + CursorTarget> DerefMut for CursorRestorer<'a, 'c, 'g, T>[src]

impl<'a, 'c: 'a, 'g: 'c, T: 'c + CursorTarget> Drop for CursorRestorer<'a, 'c, 'g, T>[src]

Auto Trait Implementations

impl<'a, 'c, 'g, T> RefUnwindSafe for CursorRestorer<'a, 'c, 'g, T> where
    T: RefUnwindSafe

impl<'a, 'c, 'g, T> Send for CursorRestorer<'a, 'c, 'g, T> where
    T: Send

impl<'a, 'c, 'g, T> Sync for CursorRestorer<'a, 'c, 'g, T> where
    T: Sync

impl<'a, 'c, 'g, T> Unpin for CursorRestorer<'a, 'c, 'g, T> where
    'c: 'a,
    'g: 'a, 

impl<'a, 'c, 'g, T> !UnwindSafe for CursorRestorer<'a, 'c, 'g, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.