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

pub struct Cursor<'c, 'g: 'c, T: 'c + CursorTarget = Window<'g>> { /* fields omitted */ }

Something that can be used to easily write text to a CursorTarget (e.g., a Window).

Implementations

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

pub fn new(target: &'c mut T) -> Self[src]

Create a cursor to act on the specified window. The cursor initially resides at location (0,0) and only uses the style of the target.

pub fn from_state(target: &'c mut T, state: CursorState) -> Self[src]

Construct a cursor from the given state to act on the specified target.

pub fn into_state(self) -> CursorState[src]

Destroy the cursor and retrieve the current state. This is useful for storing the state between draw-like calls.

pub fn position(self, x: ColIndex, y: RowIndex) -> Self[src]

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 wrapping_mode(self, wm: WrappingMode) -> Self[src]

pub fn line_start_column(self, column: ColIndex) -> Self[src]

Set the column to which to cursor will jump automatically when wrapping at the end. Furthermore, when moving left, the cursor will wrap upwards if crossing over the start column.

The default value is, of course, 0.

Examples:

use unsegen::base::*;

let mut w = ExtentEstimationWindow::with_width(Width::new(20).unwrap());
let mut cursor = Cursor::new(&mut w)
    .wrapping_mode(WrappingMode::Wrap)
    .line_start_column(ColIndex::new(5))
    .position(ColIndex::new(5), RowIndex::new(1));

cursor.move_left();
assert_eq!(cursor.get_col(), ColIndex::new(19));

cursor.move_right();
assert_eq!(cursor.get_col(), ColIndex::new(5));

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 style_modifier(self, style_modifier: StyleModifier) -> Self[src]

Set the style modifier that will be used when writing cells to the target. The modifier will be applied to the base style of the target before writing to a cell.

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<'c, 'g: 'c, T: 'c + CursorTarget> Write for Cursor<'c, 'g, T>[src]

Auto Trait Implementations

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

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

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

impl<'c, 'g, T> Unpin for Cursor<'c, 'g, T>

impl<'c, 'g, T = Window<'g>> !UnwindSafe for Cursor<'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.