Create simple terminal and buffer abstractions

This commit is contained in:
Joscha 2022-05-21 19:59:07 +02:00
parent 704bb67c7b
commit bbaea3b5bf
5 changed files with 290 additions and 8 deletions

35
examples/hello_world.rs Normal file
View file

@ -0,0 +1,35 @@
use std::io;
use crossterm::style::{ContentStyle, Stylize};
use toss::buffer::Pos;
use toss::terminal::Terminal;
fn main() -> io::Result<()> {
// Automatically enters alternate screen and enables raw mode
let mut term = Terminal::new(Box::new(io::stdout()))?;
// Must be called before rendering, otherwise the terminal has out-of-date
// size information and will present garbage.
term.autoresize()?;
// Render things to the buffer
let b = term.buffer();
b.write(
Pos::new(0, 0),
"Hello world!",
ContentStyle::default().green(),
);
b.write(
Pos::new(0, 1),
"Press any key to exit",
ContentStyle::default().on_dark_blue(),
);
// Show the buffer's contents on screen
term.present()?;
// Wait for input before exiting
let _ = crossterm::event::read();
Ok(())
}