mirror of
https://github.com/Xyverle/neutuino.git
synced 2026-06-26 23:53:13 -04:00
0.3.0, I really need to start breaking up these updates
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
|
||||
use neutuino::ansi::{
|
||||
COLORS_BG, COLORS_FG, STYLE_BOLD, STYLE_ITALIC, STYLE_RESET, STYLE_UNDERLINE,
|
||||
move_cursor_to_column, set_window_title,
|
||||
};
|
||||
use neutuino::input::{Event, KeyEvent, poll_input};
|
||||
use neutuino::os::{disable_raw_mode, enable_ansi, enable_raw_mode, get_terminal_size};
|
||||
use neutuino::prelude::*;
|
||||
use std::{io, time::Duration};
|
||||
|
||||
fn print_line_style_reset(string: &str) {
|
||||
@@ -16,13 +11,13 @@ fn main() -> io::Result<()> {
|
||||
let all_styles = format!("{STYLE_BOLD}{STYLE_ITALIC}{STYLE_UNDERLINE}");
|
||||
|
||||
enable_ansi()?;
|
||||
enable_raw_mode()?;
|
||||
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:?}");
|
||||
let terminal_size_str = format!("{:?}", terminal_size);
|
||||
print!("{}", set_window_title(terminal_size_str).unwrap());
|
||||
|
||||
let mut counter = 0;
|
||||
@@ -45,6 +40,5 @@ fn main() -> io::Result<()> {
|
||||
}
|
||||
counter = next(counter);
|
||||
}
|
||||
disable_raw_mode()?;
|
||||
Ok(())
|
||||
}
|
||||
34
examples/simple.rs
Normal file
34
examples/simple.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
|
||||
use neutuino::prelude::*;
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
thread, time,
|
||||
};
|
||||
|
||||
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()?;
|
||||
|
||||
// gets the size of the terminal
|
||||
let terminal_size = get_terminal_size()?;
|
||||
let middle = (terminal_size.0 / 2, terminal_size.1 / 2);
|
||||
|
||||
let string = "Hello, World!";
|
||||
|
||||
let adjusted_middle = (middle.0 - ((string.len() / 2) as u16), middle.1);
|
||||
|
||||
print!(
|
||||
"{COLOR_RED_BG}{}{string}",
|
||||
move_cursor_to_position(adjusted_middle.0, adjusted_middle.1)
|
||||
);
|
||||
io::stdout().flush()?; // VERY IMPORTANT!
|
||||
|
||||
thread::sleep(time::Duration::new(3, 0));
|
||||
|
||||
// no flush needed here as the program is about to end and it will be auto flushed
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user