2018-07-02 06:43:43 +10:00
|
|
|
//!
|
2018-07-02 06:40:07 +10:00
|
|
|
//! Examples of actions that could be performed with te cursor.
|
2018-01-18 09:06:45 +11:00
|
|
|
//!
|
|
|
|
|
2019-01-28 07:16:14 +11:00
|
|
|
extern crate crossterm_cursor;
|
|
|
|
|
|
|
|
use crossterm_cursor::{cursor, TerminalCursor};
|
2018-01-18 09:06:45 +11:00
|
|
|
|
|
|
|
/// Set the cursor to position X: 10, Y: 5 in the terminal.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn goto() {
|
2018-01-18 09:06:45 +11:00
|
|
|
// Get the cursor
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-01-18 09:06:45 +11:00
|
|
|
// Set the cursor to position X: 10, Y: 5 in the terminal
|
2018-07-02 06:43:43 +10:00
|
|
|
cursor.goto(10, 5);
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
/// get the cursor position
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn pos() {
|
2018-06-17 04:10:51 +10:00
|
|
|
// Get the cursor
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-06-17 04:10:51 +10:00
|
|
|
// get the cursor position.
|
2018-10-08 04:15:17 +11:00
|
|
|
let (x, y) = cursor.pos();
|
2019-01-01 05:55:48 +11:00
|
|
|
|
|
|
|
println!("{} {}", x, y);
|
2018-06-17 04:10:51 +10:00
|
|
|
}
|
|
|
|
|
2018-01-18 09:06:45 +11:00
|
|
|
/// Move the cursor 3 up | demonstration.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn move_up() {
|
2018-01-18 09:06:45 +11:00
|
|
|
// Get the cursor
|
2018-11-15 02:53:27 +11:00
|
|
|
let mut cursor = cursor();
|
2018-07-19 06:32:17 +10:00
|
|
|
|
2018-01-18 09:06:45 +11:00
|
|
|
// Move the cursor to position 3 times to the up in the terminal
|
2018-07-19 06:32:17 +10:00
|
|
|
cursor.move_up(10);
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Move the cursor 3 to the right | demonstration.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn move_right() {
|
2018-11-15 02:53:27 +11:00
|
|
|
let mut cursor = cursor();
|
2018-01-18 09:06:45 +11:00
|
|
|
// Move the cursor to position 3 times to the right in the terminal
|
|
|
|
cursor.move_right(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Move the cursor 3 down | demonstration.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn move_down() {
|
2018-11-15 02:53:27 +11:00
|
|
|
let mut cursor = cursor();
|
2018-01-18 09:06:45 +11:00
|
|
|
// Move the cursor to position 3 times to the down in the terminal
|
|
|
|
cursor.move_down(3);
|
|
|
|
}
|
|
|
|
|
2018-01-31 07:20:11 +11:00
|
|
|
/// Save and reset cursor position | demonstration..
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn safe_and_reset_position() {
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-08-15 05:40:07 +10:00
|
|
|
|
2018-01-28 04:26:08 +11:00
|
|
|
// Goto X: 5 Y: 5
|
2018-07-02 06:43:43 +10:00
|
|
|
cursor.goto(5, 5);
|
2018-01-28 04:26:08 +11:00
|
|
|
// Safe cursor position: X: 5 Y: 5
|
2018-01-31 07:20:11 +11:00
|
|
|
cursor.save_position();
|
2018-01-28 04:26:08 +11:00
|
|
|
// Goto X: 5 Y: 20
|
2018-07-02 06:43:43 +10:00
|
|
|
cursor.goto(5, 20);
|
2018-01-28 04:26:08 +11:00
|
|
|
// Print at X: 5 Y: 20.
|
2018-01-31 07:20:11 +11:00
|
|
|
println!("Yea!");
|
2018-01-28 04:26:08 +11:00
|
|
|
// Reset back to X: 5 Y: 5.
|
|
|
|
cursor.reset_position();
|
|
|
|
// Print Back at X: 5 Y: 5.
|
2018-01-31 07:20:11 +11:00
|
|
|
println!("Back");
|
2018-01-28 04:26:08 +11:00
|
|
|
|
|
|
|
println!()
|
2018-01-26 04:26:08 +11:00
|
|
|
}
|
|
|
|
|
2018-06-24 03:48:22 +10:00
|
|
|
/// Hide cursor display | demonstration.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn hide_cursor() {
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-06-24 03:48:22 +10:00
|
|
|
cursor.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Show cursor display | demonstration.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn show_cursor() {
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-06-24 03:48:22 +10:00
|
|
|
cursor.show();
|
|
|
|
}
|
|
|
|
|
2018-07-02 06:40:07 +10:00
|
|
|
/// Show cursor display, only works on certain terminals.| demonstration
|
2018-07-02 06:43:43 +10:00
|
|
|
pub fn blink_cursor() {
|
2019-01-01 05:55:48 +11:00
|
|
|
let cursor = cursor();
|
2018-06-27 04:56:34 +10:00
|
|
|
cursor.blink(false);
|
|
|
|
cursor.blink(false);
|
|
|
|
}
|
2019-01-28 07:16:14 +11:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
goto();
|
|
|
|
pos();
|
|
|
|
}
|