diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index 099548a2..9c882fad 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -100,6 +100,27 @@ where pub const fn new(writer: W) -> Self { Self { writer } } + + /// Gets the writer. + #[stability::unstable( + feature = "backend-writer", + issue = "https://github.com/ratatui-org/ratatui/pull/991" + )] + pub const fn writer(&self) -> &W { + &self.writer + } + + /// Gets the writer as a mutable reference. + /// + /// Note: writing to the writer may cause incorrect output after the write. This is due to the + /// way that the Terminal implements diffing Buffers. + #[stability::unstable( + feature = "backend-writer", + issue = "https://github.com/ratatui-org/ratatui/pull/991" + )] + pub fn writer_mut(&mut self) -> &mut W { + &mut self.writer + } } impl Write for CrosstermBackend diff --git a/src/backend/termion.rs b/src/backend/termion.rs index 46b98cc1..003d9bdb 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -85,6 +85,26 @@ where pub const fn new(writer: W) -> Self { Self { writer } } + + /// Gets the writer. + #[stability::unstable( + feature = "backend-writer", + issue = "https://github.com/ratatui-org/ratatui/pull/991" + )] + pub const fn writer(&self) -> &W { + &self.writer + } + + /// Gets the writer as a mutable reference. + /// Note: writing to the writer may cause incorrect output after the write. This is due to the + /// way that the Terminal implements diffing Buffers. + #[stability::unstable( + feature = "backend-writer", + issue = "https://github.com/ratatui-org/ratatui/pull/991" + )] + pub fn writer_mut(&mut self) -> &mut W { + &mut self.writer + } } impl Write for TermionBackend