2019-09-06 00:13:23 +10:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2019-07-25 04:10:27 +10:00
|
|
|
extern crate crossterm;
|
|
|
|
|
|
|
|
use crossterm::{
|
2019-09-06 00:13:23 +10:00
|
|
|
execute, queue, Clear, ClearType, ExecutableCommand, Goto, Output, QueueableCommand,
|
2019-07-25 04:10:27 +10:00
|
|
|
};
|
2019-09-06 00:13:23 +10:00
|
|
|
use std::io::{stdout, Write};
|
2019-07-25 04:10:27 +10:00
|
|
|
|
|
|
|
/// execute commands by using normal functions
|
|
|
|
fn execute_command_directly_using_functions() {
|
|
|
|
// single command
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = stdout().execute(Output("Text1 ".to_string()));
|
2019-07-25 04:10:27 +10:00
|
|
|
|
|
|
|
// multiple commands
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = stdout()
|
2019-07-25 04:10:27 +10:00
|
|
|
.execute(Output("Text2 ".to_string()))
|
|
|
|
.execute(Output("Text3 ".to_string()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// execute commands by using macro's
|
|
|
|
fn execute_command_directly_using_macros() {
|
|
|
|
// single command
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = execute!(stdout(), Output("Text1 ".to_string()));
|
2019-07-25 04:10:27 +10:00
|
|
|
|
|
|
|
// multiple commands
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = execute!(
|
2019-07-25 04:10:27 +10:00
|
|
|
stdout(),
|
|
|
|
Output("Text2 ".to_string()),
|
|
|
|
Output("Text 3".to_string())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// queue commands without executing them directly by using normal functions
|
|
|
|
fn later_execution_command_using_functions() {
|
|
|
|
let mut sdout = stdout();
|
|
|
|
|
|
|
|
// single command
|
|
|
|
sdout = sdout.queue(Output("Text1 ".to_string()));
|
|
|
|
|
|
|
|
// multiple commands
|
|
|
|
sdout = sdout
|
|
|
|
.queue(Clear(ClearType::All))
|
|
|
|
.queue(Goto(5, 5))
|
|
|
|
.queue(Output(
|
|
|
|
"console cleared, and moved to coord X: 5 Y: 5 ".to_string(),
|
|
|
|
));
|
|
|
|
|
|
|
|
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
|
|
|
|
|
|
|
// when you call this all commands will be executed
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = sdout.flush();
|
2019-07-25 04:10:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/// queue commands without executing them directly by using macro's
|
|
|
|
fn later_execution_command_directly_using_macros() {
|
|
|
|
let mut stdout = stdout();
|
|
|
|
|
|
|
|
// single command
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = queue!(stdout, Output("Text1 ".to_string()));
|
2019-07-25 04:10:27 +10:00
|
|
|
|
|
|
|
// multiple commands
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = queue!(
|
2019-07-25 04:10:27 +10:00
|
|
|
stdout,
|
|
|
|
Clear(ClearType::All),
|
|
|
|
Goto(5, 5),
|
|
|
|
Output("console cleared, and moved to coord X: 5 Y: 5 ".to_string())
|
|
|
|
);
|
|
|
|
|
|
|
|
::std::thread::sleep(std::time::Duration::from_millis(2000));
|
|
|
|
|
|
|
|
// when you call this all commands will be executed
|
2019-09-06 00:13:23 +10:00
|
|
|
let _ = stdout.flush();
|
2019-07-25 04:10:27 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|