use std::{thread, time::Duration};
use console_utils::{
control::{clear_line, flush, move_cursor_down, move_cursor_up, Visibility},
input::{input, multiselect, reveal, select, spinner, Empty, SpinnerType},
read::{read_key, Key},
styled::{Color, StyledText},
};
#[test]
#[ignore = "user inputs"]
fn user_input() {
let result = input::<Empty<u8>>("Enter something (integer)");
println!("{:?}", result);
}
#[test]
#[ignore = "user inputs"]
fn user_select() {
let result = select(
"Select the one option (select using Enter)",
&["Option 1", "Option 2", "Option 3"],
);
println!("{:?}", result);
let result = multiselect(
"Select an option (select using SpaceBar, then Enter)",
&["Option 1", "Option 2", "Option 3"],
);
println!("{:?}", result);
}
#[test]
#[ignore = "user inputs"]
fn user_read_key() {
println!("Input 'a' key");
let key = read_key().unwrap();
assert_eq!(key, Key::Char('a'));
}
#[test]
fn spinner_visible() {
spinner(1.0, SpinnerType::Standard);
spinner(1.0, SpinnerType::Custom(&["1", "2", "3", "4", "3", "2"]))
}
#[test]
fn reveal_visible() {
reveal(&"Hello World!".repeat(20), 0.01, Some((Key::Tab, 0.)));
}
#[test]
fn clear() {
print!("Hello World");
flush();
thread::sleep(Duration::from_secs_f64(1.0));
clear_line();
}
#[test]
fn cursor_visibility() {
println!("Hello World");
let vis = Visibility::new();
vis.hide_cursor();
thread::sleep(Duration::from_secs_f64(1.0));
}
#[test]
fn r#move() {
println!("Hello World");
println!("Hello World");
move_cursor_up(2);
thread::sleep(Duration::from_secs_f64(0.5));
move_cursor_down(1);
thread::sleep(Duration::from_secs_f64(0.5));
clear_line();
}
#[test]
fn color() {
println!("{}", StyledText::new("This is red").fg(Color::BrightRed));
println!(
"{}",
StyledText::new("This has red bg").bg(Color::BrightRed)
);
println!("{}", StyledText::new("This is bold").bold());
println!("{}", StyledText::new("This is italic").italic());
println!("{}", StyledText::new("This is underline").underline());
println!("{}", StyledText::new("This blinks").blink());
println!("{}", StyledText::new("This has reversed colors").reverse());
println!(
"{}",
StyledText::new("This is strikethrough").strikethrough()
);
println!(
"{}",
StyledText::new("This is special")
.fg(Color::BrightCyan)
.bg(Color::Yellow)
.bold()
.blink()
);
}