mirror of
https://github.com/ratatui-org/ratatui
synced 2025-02-16 14:08:44 +00:00
feat: added deref impl for backend types
This commit is contained in:
parent
ad288f5168
commit
10aeccff1a
2 changed files with 33 additions and 1 deletions
|
@ -5,7 +5,10 @@
|
|||
//! [`Backend`]: trait.Backend.html
|
||||
//! [`CrosstermBackend`]: struct.CrosstermBackend.html
|
||||
|
||||
use std::io::{self, Write};
|
||||
use std::{
|
||||
io::{self, Write},
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crossterm::{
|
||||
cursor::{Hide, MoveTo, Show},
|
||||
|
@ -71,6 +74,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<W: Write> Deref for CrosstermBackend<W> {
|
||||
type Target = W;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.buffer
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> DerefMut for CrosstermBackend<W> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.buffer
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> Backend for CrosstermBackend<W>
|
||||
where
|
||||
W: Write,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
use std::{
|
||||
fmt,
|
||||
io::{self, Write},
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -61,6 +62,20 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<W: Write> Deref for TermionBackend<W> {
|
||||
type Target = W;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.stdout
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> DerefMut for TermionBackend<W> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.stdout
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> Backend for TermionBackend<W>
|
||||
where
|
||||
W: Write,
|
||||
|
|
Loading…
Add table
Reference in a new issue