mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
70 lines
2.3 KiB
Rust
70 lines
2.3 KiB
Rust
use crate::*;
|
|
|
|
#[derive(Default)]
|
|
pub struct TuiOut {
|
|
pub buffer: Buffer,
|
|
pub area: [u16;4]
|
|
}
|
|
|
|
impl Output for TuiOut {
|
|
type Unit = u16;
|
|
type Size = [Self::Unit;2];
|
|
type Area = [Self::Unit;4];
|
|
#[inline] fn area (&self) -> [u16;4] { self.area }
|
|
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
|
|
#[inline] fn place (&mut self, area: [u16;4], content: &impl Render<TuiOut>) {
|
|
let last = self.area();
|
|
*self.area_mut() = area;
|
|
content.render(self);
|
|
*self.area_mut() = last;
|
|
}
|
|
}
|
|
|
|
impl TuiOut {
|
|
pub fn buffer_update (&mut self, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) {
|
|
buffer_update(&mut self.buffer, area, callback);
|
|
}
|
|
pub fn fill_bold (&mut self, area: [u16;4], on: bool) {
|
|
if on {
|
|
self.buffer_update(area, &|cell,_,_|cell.modifier.insert(Modifier::BOLD))
|
|
} else {
|
|
self.buffer_update(area, &|cell,_,_|cell.modifier.remove(Modifier::BOLD))
|
|
}
|
|
}
|
|
pub fn fill_bg (&mut self, area: [u16;4], color: Color) {
|
|
self.buffer_update(area, &|cell,_,_|{cell.set_bg(color);})
|
|
}
|
|
pub fn fill_fg (&mut self, area: [u16;4], color: Color) {
|
|
self.buffer_update(area, &|cell,_,_|{cell.set_fg(color);})
|
|
}
|
|
pub fn fill_ul (&mut self, area: [u16;4], color: Color) {
|
|
self.buffer_update(area, &|cell,_,_|{
|
|
cell.modifier = ratatui::prelude::Modifier::UNDERLINED;
|
|
cell.underline_color = color;
|
|
})
|
|
}
|
|
pub fn fill_char (&mut self, area: [u16;4], c: char) {
|
|
self.buffer_update(area, &|cell,_,_|{cell.set_char(c);})
|
|
}
|
|
pub fn make_dim (&mut self) {
|
|
for cell in self.buffer.content.iter_mut() {
|
|
cell.bg = ratatui::style::Color::Rgb(30,30,30);
|
|
cell.fg = ratatui::style::Color::Rgb(100,100,100);
|
|
cell.modifier = ratatui::style::Modifier::DIM;
|
|
}
|
|
}
|
|
pub fn blit (
|
|
&mut self, text: &impl AsRef<str>, x: u16, y: u16, style: Option<Style>
|
|
) {
|
|
let text = text.as_ref();
|
|
let buf = &mut self.buffer;
|
|
if x < buf.area.width && y < buf.area.height {
|
|
buf.set_string(x, y, text, style.unwrap_or(Style::default()));
|
|
}
|
|
}
|
|
#[inline]
|
|
pub fn with_rect (&mut self, area: [u16;4]) -> &mut Self {
|
|
self.area = area;
|
|
self
|
|
}
|
|
}
|