A lot of stuff

This commit is contained in:
2025-08-15 14:13:17 -04:00
parent df149ddfc8
commit b74c93601b
9 changed files with 512 additions and 141 deletions

View File

@@ -11,10 +11,10 @@ fn print_line_style_reset(string: &str) {
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()?;
enable_raw_mode()?;
enable_mouse_input()?;
// enable_kitty_keyboard();
println!("q to quit{}", move_cursor_to_column(0));
let next = |x: usize| (x + 1) % COLORS_FG.len();
@@ -26,23 +26,30 @@ fn main() -> io::Result<()> {
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 input = poll_input(Duration::new(1, 0));
let string = format!("{input:?}");
print_line_style_reset(&format!(
"{all_styles}{}{}{string}",
COLORS_FG[counter],
COLORS_BG[next(counter)]
));
match &input {
Err(e) => match e.kind() {
io::ErrorKind::TimedOut => {}
_ => {
print_line_style_reset(&string);
}
},
Ok(_) => {
print_line_style_reset(&string);
}
}
// q to quit
if input == Event::Key(Key::Char('q'), KeyType::Press, KeyMods::NONE) {
if input.is_ok()
&& input.unwrap() == Event::Key(Key::Char('q'), ButtonType::Press, Modifiers::NONE)
{
break;
}
counter = next(counter);
}
// disable_kitty_keyboard();
disable_raw_mode()?;
disable_mouse_input()?;
Ok(())
}

27
examples/raw_input.rs Normal file
View File

@@ -0,0 +1,27 @@
use neutuino::prelude::*;
use std::io::{self, IsTerminal, Read, Write};
fn main() -> io::Result<()> {
assert!(io::stdout().is_terminal(), "Not running in a terminal");
enable_ansi()?;
enable_raw_mode()?;
// enable_kitty_keyboard();
io::stdout().flush()?;
print!("\x1b[?1003h");
let mut buf = [0; 1];
let mut stdin = io::stdin();
while buf != [b'q'] {
_ = stdin.read(&mut buf);
if buf[0] > 127 || !(buf[0] as char).is_control() {
println!("{:x} \"{}\"\r", buf[0], buf[0] as char);
} else {
println!("{:x} ?\r", buf[0]);
}
}
// disable_kitty_keyboard();
disable_raw_mode()?;
print!("\x1b[?1003l");
Ok(())
}

View File

@@ -12,8 +12,8 @@ fn main() -> io::Result<()> {
enable_ansi()?;
// makes the terminal raw until this value is dropped
let _raw_terminal = RawModeHandler::new()?;
let _alt_screen = AltScreenHandler::new()?;
enable_raw_mode()?;
println!("{ALT_SCREEN_ENTER}");
// gets the size of the terminal
let terminal_size = get_terminal_size()?;
@@ -31,6 +31,9 @@ fn main() -> io::Result<()> {
thread::sleep(time::Duration::new(3, 0));
disable_raw_mode()?;
println!("{ALT_SCREEN_EXIT}");
// no flush needed here as the program is about to end and it will be auto flushed
Ok(())
}