[][src]Struct crossterm::TerminalCursor

pub struct TerminalCursor<'stdout> { /* fields omitted */ }

Struct that stores a platform-specific implementation for cursor related actions.

Check /examples/cursor in the library for more specific examples.

extern crate crossterm;
use self::crossterm::cursor;
use self::crossterm::Screen;

let mut cursor = cursor();

// Get cursor and goto pos X: 5, Y: 10
cursor.goto(5,10);

cursor.show();
cursor.hide();
cursor.blink(true);
cursor.move_left(2);

When you want to use 'cursor' on 'alternate screen' use the Screen type instead and pass it to the cursor::from_screen() function. By doing that cursor actions will be performed on the alternate screen.

Methods

impl<'stdout> TerminalCursor<'stdout>
[src]

pub fn new() -> TerminalCursor<'stdout>
[src]

Create new TerminalCursor instance whereon cursor related actions can be performed.

pub fn from_output(
    stdout: &'stdout Arc<TerminalOutput>
) -> TerminalCursor<'stdout>
[src]

Create a new instance of TerminalCursor whereon cursor related actions could be preformed on the given output.

Note

Use this function when you want your terminal to operate with a specific output. This could be useful when you have a screen which is in 'alternate mode'. And you want your actions from the TerminalCursor, created by this function, to operate on the 'alternate screen'.

Example

let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
   let terminal = TerminalCursor::from_output(&alternate.screen.stdout);
}

pub fn goto(&self, x: u16, y: u16) -> Result<()>
[src]

Goto some position (x,y) in the terminal.

let cursor = cursor();

// change the cursor to position, x: 4 and y: 5
cursor.goto(4,5);

pub fn pos(&self) -> (u16, u16)
[src]

Get current cursor position (x,y) in the terminal.

let cursor = cursor();

// get the current cursor pos
let (x,y) = cursor.pos();

pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor<'stdout>
[src]

Move the current cursor position n times up.

let cursor = cursor();

// Move the cursor to position 3 times to the up in the terminal
cursor.move_up(3);

pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout>
[src]

Move the current cursor position n times right.

let cursor = cursor();

// Move the cursor to position 3 times to the right in the terminal
cursor.move_right(3);

pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor<'stdout>
[src]

Move the current cursor position n times down.

let cursor = cursor();

// Move the cursor to position 3 times to the down in the terminal
cursor.move_down(3);

pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor<'stdout>
[src]

Move the current cursor position n times left.

let cursor = cursor();

 // Move the cursor to position 3 times to the left in the terminal
 cursor.move_left(3);

pub fn save_position(&self) -> Result<()>
[src]

Save cursor position for recall later.

Note that this position is stored program based not per instance of the Cursor struct.

let cursor = cursor();

cursor.safe_position();

pub fn reset_position(&self) -> Result<()>
[src]

Return to saved cursor position

Note that this method reset to the position set by save_position() and that this position is stored program based not per instance of the Cursor struct.

let cursor = cursor();

cursor.reset_position();

pub fn hide(&self) -> Result<()>
[src]

Hide de cursor in the console.

let cursor = cursor();
cursor.hide();

pub fn show(&self) -> Result<()>
[src]

Show the cursor in the console.


let cursor = cursor();
cursor.show();

Enable or disable blinking of the terminal.

Not all terminals are supporting this functionality. Windows versions lower than windows 10 also are not supporting this version.

let cursor = cursor();
cursor.blink(true);
cursor.blink(false);

Auto Trait Implementations

impl<'stdout> Send for TerminalCursor<'stdout>

impl<'stdout> Sync for TerminalCursor<'stdout>

Blanket Implementations

impl<T> From for T
[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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