use std::sync::atomic::{AtomicU8, Ordering};
use crate::utils::get_terminal_size;
use crossterm::{
cursor::MoveTo,
queue,
style::{Color, Print, SetForegroundColor},
};
use lazy_static::lazy_static;
lazy_static! {
pub static ref FRAME_BUFFER: FrameBuffer = FrameBuffer::new(
get_terminal_size().unwrap().x as usize,
get_terminal_size().unwrap().y as usize
);
}
#[deprecated(
since = "0.1.0",
note = "Na bro, we sticking to manually telling the terminal what to do"
)]
pub struct FrameBuffer {
pub width: usize,
pub height: usize,
pub data: Vec<AtomicU8>,
}
impl FrameBuffer {
pub fn new(width: usize, height: usize) -> Self {
let data = (0..width * height)
.map(|_| AtomicU8::new(' ' as u8))
.collect();
FrameBuffer {
width,
height,
data,
}
}
pub fn set_pixel(&self, x: usize, y: usize, c: char) {
if x < self.width && y < self.height {
self.data[y * self.width + x].store(c as u8, Ordering::Relaxed);
}
}
pub fn set_color(&self, color: Color, out: &mut impl std::io::Write) {
queue!(out, SetForegroundColor(color)).unwrap();
}
pub fn move_to(&self, x: usize, y: usize, out: &mut impl std::io::Write) {
queue!(out, MoveTo(x as u16, y as u16)).unwrap();
}
pub fn render(&self, out: &mut impl std::io::Write) {
}
}