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/widgets/clear.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/widgets/clear.rs')
| -rw-r--r-- | src/ratatui/widgets/clear.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/ratatui/widgets/clear.rs b/src/ratatui/widgets/clear.rs new file mode 100644 index 00000000..a7c8d34b --- /dev/null +++ b/src/ratatui/widgets/clear.rs @@ -0,0 +1,37 @@ +use crate::ratatui::{buffer::Buffer, layout::Rect, widgets::Widget}; + +/// A widget to clear/reset a certain area to allow overdrawing (e.g. for popups). +/// +/// This widget **cannot be used to clear the terminal on the first render** as `ratatui` assumes the +/// render area is empty. Use [`crate::Terminal::clear`] instead. +/// +/// # Examples +/// +/// ``` +/// # use ratatui::widgets::{Clear, Block, Borders}; +/// # use ratatui::layout::Rect; +/// # use ratatui::Frame; +/// # use ratatui::backend::Backend; +/// fn draw_on_clear<B: Backend>(f: &mut Frame<B>, area: Rect) { +/// let block = Block::default().title("Block").borders(Borders::ALL); +/// f.render_widget(Clear, area); // <- this will clear/reset the area first +/// f.render_widget(block, area); // now render the block widget +/// } +/// ``` +/// +/// # Popup Example +/// +/// For a more complete example how to utilize `Clear` to realize popups see +/// the example `examples/popup.rs` +#[derive(Debug, Clone)] +pub struct Clear; + +impl Widget for Clear { + fn render(self, area: Rect, buf: &mut Buffer) { + for x in area.left()..area.right() { + for y in area.top()..area.bottom() { + buf.get_mut(x, y).reset(); + } + } + } +} |
