Use Frame for rendering instead of Buffer

This commit is contained in:
Joscha 2022-05-21 22:33:37 +02:00
parent cc2f102141
commit add2f25aba
5 changed files with 85 additions and 53 deletions

View file

@ -1,32 +1,32 @@
use std::io;
use crossterm::style::{ContentStyle, Stylize};
use toss::buffer::Pos;
use toss::frame::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()))?;
let mut term = Terminal::new()?;
// 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(
// Render stuff onto the next frame
let f = term.frame();
f.write(
Pos::new(0, 0),
"Hello world!",
ContentStyle::default().green(),
);
b.write(
f.write(
Pos::new(0, 1),
"Press any key to exit",
ContentStyle::default().on_dark_blue(),
);
b.set_cursor(Some(Pos::new(16, 0)));
f.show_cursor(Pos::new(16, 0));
// Show the buffer's contents on screen
// Show the next frame on the screen
term.present()?;
// Wait for input before exiting