mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: remove redundant type param
This commit is contained in:
parent
c033a5618b
commit
df3dac183e
12 changed files with 113 additions and 125 deletions
|
|
@ -12,7 +12,7 @@ use crossterm::terminal::{
|
|||
enable_raw_mode, disable_raw_mode
|
||||
};
|
||||
|
||||
pub struct TuiContext {
|
||||
pub struct Tui {
|
||||
exited: Arc<AtomicBool>,
|
||||
buffer: usize,
|
||||
buffers: [Buffer;2],
|
||||
|
|
@ -21,7 +21,7 @@ pub struct TuiContext {
|
|||
sleep: Duration,
|
||||
poll: Duration,
|
||||
}
|
||||
impl Engine for TuiContext {
|
||||
impl Engine for Tui {
|
||||
type Handled = bool;
|
||||
type Rendered = Rect;
|
||||
fn exited (&self) -> bool {
|
||||
|
|
@ -34,7 +34,7 @@ impl Engine for TuiContext {
|
|||
fn teardown (&mut self) -> Usually<()> {
|
||||
terminal_teardown()
|
||||
}
|
||||
fn handle (&self, state: &mut impl Handle<Self, bool>) -> Usually<()> {
|
||||
fn handle (&self, state: &mut impl Handle<Self>) -> Usually<()> {
|
||||
if ::crossterm::event::poll(self.poll).is_ok() {
|
||||
let event = ::crossterm::event::read().unwrap();
|
||||
if let Event::Key(KeyEvent {
|
||||
|
|
@ -47,14 +47,14 @@ impl Engine for TuiContext {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
fn render (&mut self, state: &impl Render<Self, Rect>) -> Usually<()> {
|
||||
fn render (&mut self, state: &impl Render<Self>) -> Usually<()> {
|
||||
state.render(self).expect("render failed");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl TuiContext {
|
||||
impl Tui {
|
||||
/// Run the main loop.
|
||||
pub fn run <R: Component<TuiContext> + Sized + 'static> (
|
||||
pub fn run <R: Component<Tui> + Sized + 'static> (
|
||||
state: Arc<RwLock<R>>
|
||||
) -> Usually<Arc<RwLock<R>>> {
|
||||
let backend = CrosstermBackend::new(stdout());
|
||||
|
|
@ -149,7 +149,7 @@ pub trait TuiTarget {
|
|||
fn buffer (&mut self) -> &mut Buffer;
|
||||
}
|
||||
|
||||
impl TuiTarget for TuiContext {
|
||||
impl TuiTarget for Tui {
|
||||
fn area (&self) -> Rect {
|
||||
self.area
|
||||
}
|
||||
|
|
@ -208,8 +208,8 @@ impl<T: AsRef<str>> Blit for T {
|
|||
}
|
||||
|
||||
/// Rendering unit struct to Ratatui returns zero-sized [Rect] at render coordinates.
|
||||
impl Render<TuiContext, Rect> for () {
|
||||
fn render (&self, to: &mut TuiContext) -> Perhaps<Rect> {
|
||||
impl Render<Tui> for () {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
Ok(Some(Rect { x: to.area.x, y: to.area.y, width: 0, height: 0 }))
|
||||
}
|
||||
}
|
||||
|
|
@ -233,8 +233,8 @@ pub fn half_block (lower: bool, upper: bool) -> Option<char> {
|
|||
|
||||
pub struct FillBg(pub Color);
|
||||
|
||||
impl Render<TuiContext, Rect> for FillBg {
|
||||
fn render (&self, to: &mut TuiContext) -> Perhaps<Rect> {
|
||||
impl Render<Tui> for FillBg {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
to.fill_bg(to.area, self.0);
|
||||
Ok(Some(to.area))
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ pub trait BorderStyle {
|
|||
const W: &'static str = "";
|
||||
|
||||
#[inline]
|
||||
fn draw <'a> (&self, to: &mut TuiContext) -> Perhaps<Rect> {
|
||||
fn draw <'a> (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
self.draw_horizontal(to, None)?;
|
||||
self.draw_vertical(to, None)?;
|
||||
self.draw_corners(to, None)?;
|
||||
|
|
@ -259,7 +259,7 @@ pub trait BorderStyle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn draw_horizontal (&self, to: &mut TuiContext, style: Option<Style>) -> Usually<Rect> {
|
||||
fn draw_horizontal (&self, to: &mut Tui, style: Option<Style>) -> Usually<Rect> {
|
||||
let area = to.area();
|
||||
let buf = to.buffer();
|
||||
let style = style.or_else(||self.style_horizontal());
|
||||
|
|
@ -279,7 +279,7 @@ pub trait BorderStyle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn draw_vertical (&self, to: &mut TuiContext, style: Option<Style>) -> Usually<Rect> {
|
||||
fn draw_vertical (&self, to: &mut Tui, style: Option<Style>) -> Usually<Rect> {
|
||||
let area = to.area();
|
||||
let buf = to.buffer();
|
||||
let style = style.or_else(||self.style_vertical());
|
||||
|
|
@ -291,7 +291,7 @@ pub trait BorderStyle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn draw_corners (&self, to: &mut TuiContext, style: Option<Style>) -> Usually<Rect> {
|
||||
fn draw_corners (&self, to: &mut Tui, style: Option<Style>) -> Usually<Rect> {
|
||||
let area = to.area();
|
||||
let buf = to.buffer();
|
||||
let style = style.or_else(||self.style_corners());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue