Crossterm interface

This commit is contained in:
2026-07-14 13:52:41 -04:00
parent 3428beef8e
commit fd7192e111
4 changed files with 63 additions and 9 deletions
+38 -2
View File
@@ -1,6 +1,10 @@
use std::fmt::Display;
use std::{fmt::Display, io::stdout};
use crate::unit::{Point, Rect};
use crate::{
layout::Allocation,
unit::{Point, Rect},
widget::Widget,
};
pub enum Instr {
DrawText(Point, String),
@@ -55,3 +59,35 @@ impl From<Rect> for Point {
}
}
}
impl Allocation {
pub fn draw<W: Widget>(&self, index: usize, widget: W) {
let mut scope = RenderScope::new(self.widget_alloc[index]);
widget.render(&mut scope);
scope.draw();
}
}
impl RenderScope {
pub fn draw(self) {
for inst in self.draw_instructions {
match inst {
Instr::DrawText(point, text) => {
for (i, line) in text.lines().enumerate() {
print_at(
self.rect.x + point.x,
self.rect.y + point.y + i as u16,
line,
);
}
}
Instr::DrawOutline(rect) => {}
}
}
}
}
pub fn print_at(x: u16, y: u16, text: &str) {
crossterm::execute!(stdout(), crossterm::cursor::MoveTo(x, y)).unwrap();
println!("{text}");
}