From 530cba2bc8896a6bce092a97c5b66c76cd839c2d Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 15 Sep 2024 17:30:27 +0300 Subject: [PATCH] (and broken) --- crates/tek_core/src/tui.rs | 186 ++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 104 deletions(-) diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index 6184794f..a6b0eb59 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -15,18 +15,8 @@ pub struct Tui { exited: Arc, buffer: Buffer, backend: CrosstermBackend, - event: RwLock>, area: [u16;4], } -pub struct TuiInput { - event: TuiEvent, - exited: Arc, -} -pub struct TuiOutput { - pub buffer: Buffer, - pub area: [u16;4], -} - impl Engine for Tui { type Unit = u16; type Size = [Self::Unit;2]; @@ -55,99 +45,6 @@ impl Engine for Tui { disable_raw_mode().map_err(Into::into) } } -impl Input for TuiInput { - type Event = TuiEvent; - fn event (&self) -> &TuiEvent { - &self.event - } - fn is_done (&self) -> bool { - self.exited.fetch_and(true, Ordering::Relaxed) - } - fn done (&self) { - self.exited.store(true, Ordering::Relaxed); - } -} -//impl Output for Tui { - //#[inline] fn area (&self) -> ::Area { - //self.area - //} - //#[inline] fn area_mut (&mut self) -> &mut ::Area { - //&mut self.area - //} - //#[inline] fn render_in (&mut self, - //area: ::Area, - //widget: &dyn Widget - //) -> Perhaps<::Area> { - //let last = self.area(); - //*self.area_mut() = area; - //let next = widget.render(self)?; - //*self.area_mut() = last; - //Ok(next) - //} -//} -impl Output for TuiOutput { - #[inline] fn area (&self) -> [u16;4] { - self.area - } - #[inline] fn area_mut (&mut self) -> &mut [u16;4] { - &mut self.area - } - #[inline] fn render_in (&mut self, - area: [u16;4], - widget: &dyn Widget - ) -> Usually<()> { - let last = self.area(); - *self.area_mut() = area; - widget.render(self)?; - *self.area_mut() = last; - Ok(()) - } -} -impl TuiOutput { - 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_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, x: u16, y: u16, style: Option