pub mod align;
pub mod cache;
pub mod conceal;
pub mod focus;
pub mod frame;
pub mod indent;
pub mod layout;
pub mod numbers;
pub mod pane;
pub mod print;
pub mod splash;
pub mod markdown;
pub mod theme;
use std::ops::Range;
use theme::Style;
#[derive(Clone, Debug, PartialEq)]
pub struct StyledSpan {
pub range: Range<usize>,
pub style: Style,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Placement {
pub x: u16,
pub y: u16,
pub cols: u16,
pub rows: u16,
pub line: usize,
pub index: usize,
}
impl Placement {
pub fn fits_in(&self, term: (u16, u16)) -> bool {
let (cols, rows) = term;
self.y + self.rows <= rows && self.x + self.cols <= cols
}
pub fn overlaps(&self, r: ratatui::layout::Rect) -> bool {
self.x < r.x + r.width
&& r.x < self.x + self.cols
&& self.y < r.y + r.height
&& r.y < self.y + self.rows
}
}
#[cfg(test)]
mod tests {
use super::Placement;
fn at(x: u16, y: u16, cols: u16, rows: u16) -> Placement {
Placement { x, y, cols, rows, line: 0, index: 0 }
}
#[test]
fn a_picture_yields_to_an_overlay_it_touches() {
use ratatui::layout::Rect;
let pic = at(10, 5, 40, 10); assert!(pic.overlaps(Rect { x: 20, y: 8, width: 30, height: 3 }), "straddling it");
assert!(pic.overlaps(Rect { x: 0, y: 0, width: 80, height: 24 }), "covering it");
assert!(pic.overlaps(Rect { x: 49, y: 14, width: 4, height: 3 }), "one shared cell");
assert!(!pic.overlaps(Rect { x: 50, y: 5, width: 10, height: 10 }), "just to the right");
assert!(!pic.overlaps(Rect { x: 10, y: 15, width: 40, height: 3 }), "just below");
assert!(!pic.overlaps(Rect { x: 10, y: 0, width: 40, height: 5 }), "just above");
}
#[test]
fn a_picture_that_would_run_off_the_screen_does_not_fit() {
let term = (80, 24);
assert!(at(0, 0, 80, 24).fits_in(term), "exactly filling it is fitting");
assert!(at(4, 4, 60, 18).fits_in(term));
assert!(!at(4, 20, 60, 5).fits_in(term), "one row past the bottom");
assert!(!at(40, 4, 60, 5).fits_in(term), "and past the right edge");
assert!(!at(0, 23, 10, 2).fits_in(term));
}
}