Create simple terminal and buffer abstractions
This commit is contained in:
parent
704bb67c7b
commit
bbaea3b5bf
5 changed files with 290 additions and 8 deletions
35
examples/hello_world.rs
Normal file
35
examples/hello_world.rs
Normal 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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue