mirror of
https://github.com/Xyverle/neutuino.git
synced 2026-06-26 23:33:13 -04:00
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
#![warn(clippy::all, clippy::pedantic)]
|
|
|
|
use neutuino::prelude::*;
|
|
use std::{io, time::Duration};
|
|
use std::io::IsTerminal;
|
|
|
|
fn print_line_style_reset(string: &str) {
|
|
println!("{}{}{}", string, STYLE_RESET, move_cursor_to_column(0));
|
|
}
|
|
|
|
fn main() -> io::Result<()> {
|
|
assert!(io::stdout().is_terminal(), "Not running in a terminal");
|
|
|
|
let all_styles = format!("{STYLE_BOLD}{STYLE_ITALIC}{STYLE_UNDERLINE}");
|
|
|
|
enable_ansi()?;
|
|
let _raw_terminal = RawModeHandler::new()?;
|
|
|
|
println!("q to quit{}", move_cursor_to_column(0));
|
|
let next = |x: usize| (x + 1) % COLORS_FG.len();
|
|
|
|
let terminal_size = get_terminal_size()?;
|
|
let terminal_size_str = format!("{:?}", terminal_size);
|
|
print!("{}", set_window_title(terminal_size_str).unwrap());
|
|
|
|
let mut counter = 0;
|
|
|
|
loop {
|
|
let mut input = Err(io::ErrorKind::Other.into());
|
|
while input.is_err() {
|
|
input = poll_input(Duration::new(1, 0));
|
|
}
|
|
let input = input.unwrap();
|
|
let string = format!("{input:?}");
|
|
print_line_style_reset(&format!(
|
|
"{all_styles}{}{}{string}",
|
|
COLORS_FG[counter],
|
|
COLORS_BG[next(counter)]
|
|
));
|
|
// q to quit
|
|
if input == Event::Key(KeyEvent::Char('q')) {
|
|
break;
|
|
}
|
|
counter = next(counter);
|
|
}
|
|
Ok(())
|
|
}
|