diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-03-31 22:57:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-31 22:57:37 +0100 |
| commit | a515b06bcb556c1be2d0fc3095cd778d413fe40d (patch) | |
| tree | 4b544de9aa53d6976177c08b91aa3943ef4d9e92 /src/ratatui/backend/mod.rs | |
| parent | feat: add github action to test the nix builds (#833) (diff) | |
| download | atuin-a515b06bcb556c1be2d0fc3095cd778d413fe40d.zip | |
Vendor ratatui temporarily (#835)
* Vendor ratatui temporarily
Once https://github.com/tui-rs-revival/ratatui/pull/114 has been merged,
we can undo this! But otherwise we can't publish to crates.io with a git
dependency.
* make tests pass
* Shush.
* these literally just fail in nix, nowhere else
idk how to work with nix properly, and they're also not our tests
Diffstat (limited to 'src/ratatui/backend/mod.rs')
| -rw-r--r-- | src/ratatui/backend/mod.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ratatui/backend/mod.rs b/src/ratatui/backend/mod.rs new file mode 100644 index 00000000..a360db18 --- /dev/null +++ b/src/ratatui/backend/mod.rs @@ -0,0 +1,58 @@ +use std::io; + +use crate::ratatui::buffer::Cell; +use crate::ratatui::layout::Rect; + +#[cfg(feature = "termion")] +mod termion; +#[cfg(feature = "termion")] +pub use self::termion::TermionBackend; + +mod crossterm; +pub use self::crossterm::CrosstermBackend; + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum ClearType { + All, + AfterCursor, + BeforeCursor, + CurrentLine, + UntilNewLine, +} + +pub trait Backend { + fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error> + where + I: Iterator<Item = (u16, u16, &'a Cell)>; + + /// Insert `n` line breaks to the terminal screen + fn append_lines(&mut self, n: u16) -> io::Result<()> { + // to get around the unused warning + let _n = n; + Ok(()) + } + + fn hide_cursor(&mut self) -> Result<(), io::Error>; + fn show_cursor(&mut self) -> Result<(), io::Error>; + fn get_cursor(&mut self) -> Result<(u16, u16), io::Error>; + fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error>; + + /// Clears the whole terminal screen + fn clear(&mut self) -> Result<(), io::Error>; + + /// Clears a specific region of the terminal specified by the [`ClearType`] parameter + fn clear_region(&mut self, clear_type: ClearType) -> Result<(), io::Error> { + match clear_type { + ClearType::All => self.clear(), + ClearType::AfterCursor + | ClearType::BeforeCursor + | ClearType::CurrentLine + | ClearType::UntilNewLine => Err(io::Error::new( + io::ErrorKind::Other, + format!("clear_type [{clear_type:?}] not supported with this backend"), + )), + } + } + fn size(&self) -> Result<Rect, io::Error>; + fn flush(&mut self) -> Result<(), io::Error>; +} |
