use std::cell::Cell;
use super::widgets::{centered, scrollbar};
use super::{Event, Frame, Keymap, Rect, Widget};
use crate::Spinner;
use crate::style::palette::{BERRY, MUTED, RED, ROSE, TRACK};
use crate::style::{ColorMode, Rgb, bold, color_mode, mix, paint, sample};
use crate::table::{Align, Table};
use crate::text;
#[derive(Clone, Debug, Default)]
pub struct GridState {
row: usize,
column: usize,
top: Cell<usize>,
last_column: Cell<usize>,
keymap: Keymap,
}
impl GridState {
pub fn new() -> Self {
GridState::default()
}
pub fn row(&self) -> usize {
self.row
}
pub fn select(&mut self, row: usize) {
self.row = row;
}
#[must_use]
pub fn keymap(mut self, keymap: Keymap) -> Self {
self.keymap = keymap;
self
}
pub fn handle(&mut self, len: usize, event: &Event) -> bool {
super::navigate(&mut self.row, len, event, self.keymap)
}
pub fn column(&self) -> usize {
self.column
}
pub fn scroll_right(&mut self) -> bool {
let moved = self.column < self.last_column.get();
if moved {
self.column += 1;
}
moved
}
pub fn scroll_left(&mut self) -> bool {
let moved = self.column > 0;
self.column = self.column.saturating_sub(1);
moved
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Line<'g> {
Heading(&'g str),
Row(usize),
}
#[derive(Clone, Debug)]
enum Body {
Rows,
Loading,
Error(String),
}
#[derive(Clone, Debug)]
pub struct Grid<'a> {
headers: Vec<String>,
rows: Vec<Vec<String>>,
headings: Vec<(usize, String)>,
align: Vec<(usize, Align)>,
limits: Vec<(usize, usize)>,
cursor: Option<&'a GridState>,
focused: bool,
striped: bool,
blank: bool,
sorted: Option<(usize, bool)>,
body: Body,
empty: String,
fill: Option<usize>,
}
impl<'a> Grid<'a> {
pub fn new<S: Into<String>>(headers: impl IntoIterator<Item = S>) -> Self {
Grid {
headers: headers.into_iter().map(Into::into).collect(),
rows: Vec::new(),
headings: Vec::new(),
align: Vec::new(),
limits: Vec::new(),
cursor: None,
focused: true,
striped: false,
blank: false,
sorted: None,
body: Body::Rows,
empty: "nothing here yet".into(),
fill: None,
}
}
#[must_use]
pub fn fill(mut self, column: usize) -> Self {
self.fill = Some(column);
self
}
#[must_use]
pub fn row<S: Into<String>>(mut self, cells: impl IntoIterator<Item = S>) -> Self {
let cells: Vec<String> = cells.into_iter().map(Into::into).collect();
crate::table::check_row("Grid", &self.headers, cells.len(), self.rows.len());
self.rows.push(cells);
self
}
#[must_use]
pub fn heading(mut self, text: impl Into<String>) -> Self {
self.headings.push((self.rows.len(), text.into()));
self
}
#[must_use]
pub fn align(mut self, column: usize, align: Align) -> Self {
self.align.push((column, align));
self
}
#[must_use]
pub fn max_width(mut self, column: usize, cols: usize) -> Self {
self.limits.push((column, cols.max(1)));
self
}
#[must_use]
pub fn state(mut self, state: &'a GridState) -> Self {
self.cursor = Some(state);
self
}
#[must_use]
pub fn focused(mut self, focused: bool) -> Self {
self.focused = focused;
self
}
#[must_use]
pub fn striped(mut self) -> Self {
self.striped = true;
self
}
#[must_use]
pub fn blank_cells(mut self) -> Self {
self.blank = true;
self
}
#[must_use]
pub fn sorted(mut self, column: usize) -> Self {
self.sorted = Some((column, false));
self
}
#[must_use]
pub fn sorted_desc(mut self, column: usize) -> Self {
self.sorted = Some((column, true));
self
}
#[must_use]
pub fn loading(mut self, loading: bool) -> Self {
if loading {
self.body = Body::Loading;
} else if matches!(self.body, Body::Loading) {
self.body = Body::Rows;
}
self
}
#[must_use]
pub fn error(mut self, message: impl Into<String>) -> Self {
self.body = Body::Error(message.into());
self
}
#[must_use]
pub fn empty(mut self, message: impl Into<String>) -> Self {
self.empty = message.into();
self
}
pub fn row_at(&self, area: Rect, x: usize, y: usize) -> Option<usize> {
if !area.contains(x, y) || y < area.y + 2 || !matches!(self.body, Body::Rows) {
return None;
}
let top = self.cursor.map_or(0, |c| c.top.get());
match self.line_at(top + y - area.y - 2) {
Some(Line::Row(i)) => Some(i),
_ => None,
}
}
fn total(&self) -> usize {
self.rows.len() + self.headings.len()
}
fn line_at(&self, line: usize) -> Option<Line<'_>> {
for (k, (row, text)) in self.headings.iter().enumerate() {
let at = row + k;
if line == at {
return Some(Line::Heading(text));
}
if line < at {
return Some(Line::Row(line - k));
}
}
let row = line.checked_sub(self.headings.len())?;
(row < self.rows.len()).then_some(Line::Row(row))
}
fn line_of(&self, row: usize) -> usize {
row + self.headings.iter().filter(|h| h.0 <= row).count()
}
fn heading_of(&self, row: usize) -> Option<usize> {
let k = self.headings.iter().rposition(|h| h.0 <= row)?;
Some(self.headings[k].0 + k)
}
fn headers(&self) -> Vec<String> {
let mut headers = self.headers.clone();
if let Some((col, desc)) = self.sorted {
if let Some(h) = headers.get_mut(col) {
h.push_str(if desc { " ▼" } else { " ▲" });
}
}
headers
}
fn table(
&self,
headers: &[String],
widths: &[usize],
fill: Option<(usize, usize)>,
rows: impl Iterator<Item = usize>,
) -> Table {
let aligns: Vec<Align> = (0..widths.len()).map(|c| self.column_align(c)).collect();
let headers = widths.iter().zip(&aligns).enumerate().map(|(c, (&w, &align))| {
let header = headers.get(c).map_or("", String::as_str);
match align {
Align::Left => text::pad(header, w),
Align::Right => text::pad_left(header, w),
}
});
let mut table = Table::new(headers);
for row in rows {
table = table.row(self.rows[row].iter().cloned());
}
for (col, align) in aligns.into_iter().enumerate() {
table = table.align(col, align);
}
for &(col, cols) in self.limits.iter().chain(&fill) {
table = table.max_width(col, cols);
}
if self.blank {
table = table.blank_cells();
}
table
}
fn column_align(&self, column: usize) -> Align {
if let Some(&(_, align)) = self.align.iter().rev().find(|a| a.0 == column) {
return align;
}
let numeric = self.rows.iter().filter_map(|r| r.get(column)).all(|cell| {
let stripped;
let cell = if cell.contains('\x1b') {
stripped = text::strip_ansi(cell);
stripped.trim()
} else {
cell.trim()
};
cell.is_empty() || cell.starts_with(|ch: char| ch.is_ascii_digit() || ch == '-' || ch == '$')
});
if numeric && !self.rows.is_empty() {
Align::Right
} else {
Align::Left
}
}
fn widths(&self, headers: &[String]) -> Vec<usize> {
let cols = self.rows.iter().map(Vec::len).chain([headers.len()]).max().unwrap_or(0);
(0..cols)
.map(|c| {
let limit = self.limits.iter().rev().find(|l| l.0 == c).map(|l| l.1);
self.rows
.iter()
.chain([&headers.to_vec()])
.filter_map(|r| r.get(c))
.map(|cell| {
let w = width(cell);
limit.map_or(w, |l| w.min(l))
})
.max()
.unwrap_or(0)
.max(1)
})
.collect()
}
}
fn width(cell: &str) -> usize {
if cell.is_ascii() && !cell.contains('\x1b') {
cell.bytes().filter(|&b| b != 0).count()
} else {
text::width(cell)
}
}
fn band(focused: bool) -> Rgb {
mix(TRACK, BERRY, if focused { 0.35 } else { 0.16 })
}
const STRIPE: Rgb = Rgb(38, 32, 36);
impl Grid<'_> {
fn spare(&self, area: Rect, widths: &[usize]) -> Option<(usize, usize)> {
let column = self.fill?;
let width = *widths.get(column)?;
let inner = widths.iter().sum::<usize>() + 3 * widths.len().saturating_sub(1);
let overflow = matches!(self.body, Body::Rows) && self.total() > area.height.saturating_sub(2);
let room = area.width.saturating_sub(2 + overflow as usize);
let spare = room.checked_sub(inner).filter(|&s| s > 0)?;
Some((column, width + spare))
}
}
impl Widget for Grid<'_> {
fn render(&self, area: Rect, frame: &mut Frame) {
if area.is_empty() {
return;
}
let headers = self.headers();
let mut widths = self.widths(&headers);
let fill = self.spare(area, &widths);
if let Some((column, cols)) = fill {
widths[column] = cols;
}
self.draw(area, frame, &headers, &widths, fill);
}
fn size(&self) -> Option<(usize, usize)> {
let widths = self.widths(&self.headers());
let inner = widths.iter().sum::<usize>() + 3 * widths.len().saturating_sub(1);
let headings = self.headings.iter().map(|h| text::width(&h.1)).max().unwrap_or(0);
Some((inner.max(headings) + 2, self.total().max(1) + 2))
}
}
impl Grid<'_> {
fn draw(&self, area: Rect, frame: &mut Frame, headers: &[String], widths: &[usize], fill: Option<(usize, usize)>) {
let n = self.rows.len();
let rows = matches!(self.body, Body::Rows) && n > 0;
let body = Rect::new(area.x, area.y + 2, area.width, area.height.saturating_sub(2));
let chosen = self.cursor.filter(|_| rows).map(|c| c.row.min(n - 1));
let total = self.total();
let overflow = rows && total > body.height;
let content = Rect::new(
area.x + 2,
area.y,
area.width.saturating_sub(2 + overflow as usize),
area.height,
);
let inner = widths.iter().sum::<usize>() + 3 * widths.len().saturating_sub(1);
let starts: Vec<usize> = widths
.iter()
.scan(0, |at, w| {
let start = *at;
*at += w + 3;
Some(start)
})
.collect();
let last_column = starts
.iter()
.position(|&s| inner - s <= content.width)
.unwrap_or(starts.len().saturating_sub(1));
let column = self.cursor.map_or(0, |c| c.column.min(last_column));
let skip = starts.get(column).copied().unwrap_or(0);
let mut top = self.cursor.map_or(0, |c| c.top.get());
if let Some(chosen) = chosen {
let at = self.line_of(chosen);
if at < top {
top = at;
} else if at >= top + body.height {
top = at + 1 - body.height;
}
if let Some(heading) = self.heading_of(chosen) {
if heading < top && at - heading < body.height {
top = heading;
}
}
}
top = top.min(total.saturating_sub(body.height));
if let Some(c) = self.cursor {
c.top.set(top);
c.last_column.set(last_column);
}
let showing: Vec<Line> = (top..total.min(top + body.height))
.filter_map(|l| self.line_at(l))
.collect();
let shown: Vec<usize> = match self.body {
Body::Rows => showing
.iter()
.filter_map(|l| match l {
Line::Row(i) => Some(*i),
Line::Heading(_) => None,
})
.collect(),
_ => Vec::new(),
};
let lines = self
.table(headers, widths, fill, shown.iter().copied())
.lines()
.into_lines();
let line = |i: usize| lines.get(i).map(|l| l.chars().skip(2).collect::<String>());
for row in 0..2 {
frame.print_from(content, row, &line(row).unwrap_or_default(), skip);
}
if area.height > 1 && content.width > 0 {
if skip > 0 {
frame.print(Rect::new(area.x + 1, area.y + 1, 1, 1), 0, &paint(ROSE, "‹"));
}
if inner - skip > content.width {
let right = content.x + content.width - 1;
frame.print(Rect::new(right, area.y + 1, 1, 1), 0, &paint(ROSE, "›"));
}
}
match &self.body {
Body::Error(message) => {
let message = format!("{} {}", paint(RED, "✕"), paint(RED, message));
centered(frame, body, &message);
}
Body::Loading => skeleton(frame, body, content, widths, skip),
Body::Rows if n == 0 => centered(frame, body, &paint(MUTED, &self.empty)),
Body::Rows => {
let across = Rect::new(area.x, 0, area.width - overflow as usize, 1);
for (row, &item) in showing.iter().enumerate() {
let y = body.y + row;
let strip = Rect { y, ..across };
let i = match item {
Line::Row(i) => i,
Line::Heading(heading) => {
let fitted = if text::width(heading) > content.width {
text::truncate(&text::strip_ansi(heading), content.width)
} else {
heading.to_string()
};
frame.print(Rect { y, ..content }, 0, &bold(&paint(ROSE, &fitted)));
continue;
}
};
if Some(i) == chosen {
frame.tint(strip, band(self.focused));
let mark = if color_mode() == ColorMode::None { "›" } else { "▌" };
let color = if self.focused { ROSE } else { MUTED };
frame.print(strip, 0, &paint(color, mark));
} else if self.striped && i % 2 == 1 {
frame.tint(strip, STRIPE);
}
let at = shown.iter().position(|&r| r == i).unwrap_or(usize::MAX);
let l = line(at.saturating_add(2)).unwrap_or_default();
frame.print_from(Rect { y, ..content }, 0, &l, skip);
}
if overflow {
let bar = Rect::new(area.x + area.width - 1, body.y, 1, body.height);
scrollbar(frame, bar, top, total);
}
}
}
}
}
fn skeleton(frame: &mut Frame, body: Rect, content: Rect, widths: &[usize], skip: usize) {
frame.animate_at(super::widgets::BUSY_FPS);
let t = frame.ambient_time();
if color_mode() != ColorMode::None {
let sweep = (t * 0.8).rem_euclid(1.6) as f32 - 0.3;
for row in 0..body.height.min(8) {
let mut line = String::new();
let mut col: usize = 0;
for (c, w) in widths.iter().enumerate() {
let seed = crate::widgets::noise((row * 31 + c) as u32, 7);
let len = ((*w as f32) * (0.45 + 0.55 * seed)).round().max(1.0) as usize;
for x in 0..*w {
let at = col.saturating_sub(skip) as f32 / content.width.max(1) as f32;
col += 1;
let glow = (1.0f32 - ((at - sweep).abs() * 4.0)).max(0.0);
let ink = sample(&[mix(TRACK, BERRY, 0.25), mix(TRACK, ROSE, 0.6)], glow);
line.push_str(&if x < len { paint(ink, "━") } else { " ".into() });
}
line.push_str(" ");
col += 3;
}
frame.print_from(
Rect {
y: body.y + row,
..content
},
0,
&line,
skip,
);
}
}
let spinner = Spinner::Dots.frame(t);
centered(frame, body, &format!("{spinner} {}", paint(MUTED, "loading…")));
}
#[cfg(test)]
mod tests {
use super::*;
fn drawn(w: usize, h: usize, grid: Grid) -> String {
crate::set_color_mode(ColorMode::None);
let mut f = Frame::new(w, h);
f.render(f.area(), grid);
f.snapshot().plain()
}
#[test]
fn only_the_rows_showing_are_laid_out_and_they_line_up_as_if_all_were() {
let mut grid = Grid::new(["id", "name"]);
let mut table = Table::new(["id", "name"]);
for i in 0..1000 {
let row = [
if i == 999 {
"n/a".to_string()
} else {
(i * 7).to_string()
},
format!("row {i}"),
];
grid = grid.row(row.clone());
table = table.row(row);
}
let mut cursor = GridState::new();
cursor.select(500);
let shown = drawn(30, 6, grid.clone().state(&cursor));
crate::set_color_mode(ColorMode::None);
let all = table.lines().plain();
let all: Vec<&str> = all.lines().collect();
let want: Vec<String> = all[..2]
.iter()
.chain(&all[499..503])
.map(|l| format!(" {}", &l[2..]).trim_end().to_string())
.collect();
let shown: Vec<String> = shown
.lines()
.map(|l| {
l.replacen('›', " ", 1)
.trim_end_matches(['│', '┃'])
.trim_end()
.to_string()
})
.collect();
assert_eq!(shown, want);
}
#[test]
fn widths_follow_limits_and_sort_marks() {
let grid = Grid::new(["a", "bb"]).row(["long cell", "x"]).max_width(0, 4).sorted(1);
assert_eq!(grid.widths(&grid.headers()), [4, 4]);
assert_eq!(grid.size(), Some((13, 3)));
assert_eq!(drawn(14, 3, grid), " a bb ▲\n ┈┈┈┈┈┈┈┈┈┈┈\n lon… x");
}
#[test]
fn a_fill_column_takes_the_spare_width() {
let grid = || {
Grid::new(["name", "n"])
.row(["a-long-name", "1"])
.max_width(0, 6)
.fill(0)
};
assert_eq!(
drawn(24, 3, grid()),
" name n\n ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n a-long-name 1"
);
assert_eq!(drawn(12, 3, grid()), " name n\n ┈┈┈┈┈┈┈┈┈┈\n a-lon… 1");
}
#[test]
fn empty_cells_can_be_blank() {
let grid = || Grid::new(["name", "owner"]).row(["api", ""]).row(["web", "ops"]);
assert_eq!(
drawn(16, 4, grid()),
" name owner\n ┈┈┈┈┈┈┈┈┈┈┈┈\n api ·\n web ops"
);
assert_eq!(
drawn(16, 4, grid().blank_cells()),
" name owner\n ┈┈┈┈┈┈┈┈┈┈┈┈\n api\n web ops"
);
}
fn grouped(cursor: &GridState) -> Grid<'_> {
let mut grid = Grid::new(["name"]).state(cursor);
for i in 0..6 {
if i % 3 == 0 {
grid = grid.heading(if i == 0 { "a" } else { "b" });
}
grid = grid.row([format!("r{i}")]);
}
grid
}
#[test]
fn headings_sit_between_rows_and_the_cursor_counts_rows_only() {
let mut cursor = GridState::new();
cursor.select(3);
let shown = drawn(12, 10, grouped(&cursor));
assert_eq!(shown, " name\n ┈┈┈┈\n a\n r0\n r1\n r2\n b\n› r3\n r4\n r5");
cursor.select(2);
assert!(cursor.handle(6, &Event::Key(super::super::Key::Down)));
assert_eq!(cursor.row(), 3);
assert_eq!(grouped(&cursor).size(), Some((6, 10)));
}
#[test]
fn scrolling_keeps_the_cursor_row_and_its_heading_in_view() {
let mut cursor = GridState::new();
let mut at = |row: usize| {
cursor.select(row);
let shown = drawn(12, 5, grouped(&cursor));
let body: Vec<String> = shown
.lines()
.skip(2)
.map(|l| l.trim_end_matches(['│', '┃']).trim().to_string())
.collect();
(body.join(" "), cursor.top.get())
};
assert_eq!(at(0), ("a › r0 r1".into(), 0));
assert_eq!(at(3), ("r2 b › r3".into(), 3));
assert_eq!(at(5), ("r3 r4 › r5".into(), 5));
assert_eq!(at(3), ("b › r3 r4".into(), 4));
assert_eq!(at(2), ("› r2 b r3".into(), 3));
assert_eq!(at(1), ("a r0 › r1".into(), 0));
}
#[test]
fn clicks_on_headings_find_no_row() {
let mut cursor = GridState::new();
cursor.select(5);
let area = Rect::new(0, 0, 12, 5);
drawn(12, 5, grouped(&cursor));
cursor.select(3);
drawn(12, 5, grouped(&cursor));
let grid = grouped(&cursor);
assert_eq!(cursor.top.get(), 4);
assert_eq!(grid.row_at(area, 3, 2), None, "the heading");
assert_eq!(grid.row_at(area, 3, 3), Some(3));
assert_eq!(grid.row_at(area, 3, 4), Some(4));
let flat = Grid::new(["n"]).heading("only").row(["x"]);
assert_eq!(flat.row_at(area, 3, 2), None);
assert_eq!(flat.row_at(area, 3, 3), Some(0));
assert_eq!(flat.row_at(area, 3, 4), None);
}
#[test]
fn headings_work_with_fill_and_sideways_scrolling() {
let grid = Grid::new(["name", "n"])
.heading("group")
.row(["a-long-name", "1"])
.max_width(0, 6)
.fill(0);
assert_eq!(
drawn(24, 4, grid),
" name n\n ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n group\n a-long-name 1"
);
let grid = Grid::new(["name", "n"]).heading("group").row(["abc", "1"]).fill(0);
assert_eq!(drawn(12, 3, grid), " name n\n ┈┈┈┈┈┈┈┈┈\n group ┃");
let mut cursor = GridState::new();
fn services(c: &GridState) -> Grid<'_> {
Grid::new(["name", "env", "owner"])
.heading("services")
.row(["api", "production", "platform"])
.state(c)
}
drawn(16, 4, services(&cursor));
assert!(cursor.scroll_right());
let shown = drawn(16, 4, services(&cursor));
assert_eq!(shown.lines().nth(2), Some(" services"), "{shown}");
assert!(
shown
.lines()
.nth(3)
.is_some_and(|l| l.contains("production") && !l.contains("api")),
"{shown}"
);
}
#[test]
fn states_instead_of_rows() {
let shown = drawn(20, 5, Grid::new(["name"]).error("couldn't read"));
assert_eq!(shown.lines().nth(3), Some(" ✕ couldn't read"));
let shown = drawn(20, 5, Grid::new(["name"]));
assert!(shown.contains("nothing here yet"), "{shown}");
let shown = drawn(20, 5, Grid::new(["name"]).row(["x"]).loading(true));
assert!(shown.contains("loading…") && !shown.contains('x'), "{shown}");
}
#[test]
fn rows_are_found_by_where_they_are() {
let mut cursor = GridState::new();
cursor.select(9);
let rows: Vec<String> = (0..10).map(|i| i.to_string()).collect();
let grid = rows
.iter()
.fold(Grid::new(["n"]), |g, r| g.row([r.as_str()]))
.state(&cursor);
let area = Rect::new(0, 0, 10, 5);
drawn(10, 5, grid.clone());
assert_eq!(cursor.top.get(), 7);
assert_eq!(grid.row_at(area, 3, 2), Some(7));
assert_eq!(grid.row_at(area, 3, 1), None);
assert_eq!(grid.row_at(area, 30, 2), None);
}
#[test]
fn a_fill_column_without_a_header_still_fills() {
let grid = Grid::new(["name", ""]).row(["api", "extra"]).fill(1);
assert_eq!(drawn(20, 3, grid), " name\n ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈\n api extra");
}
#[test]
fn alignment_sort_marks_and_messages() {
let grid = Grid::new(["n", "name"])
.row(["1", "a"])
.align(0, Align::Left)
.sorted_desc(0);
assert_eq!(drawn(12, 3, grid), " n ▼ name\n ┈┈┈┈┈┈┈┈┈┈\n 1 a");
let none = Grid::new(["name"]).empty("no services").loading(false).sorted(5);
assert!(drawn(20, 3, none).ends_with("no services"));
drawn(0, 0, Grid::new(["x"]));
}
#[test]
fn long_headings_are_cut_to_fit() {
let grid = Grid::new(["n"]).heading("a heading much too long").row(["1"]);
let shown = drawn(10, 4, grid);
assert!(shown.lines().nth(2).unwrap().ends_with('…'), "{shown}");
}
#[test]
fn a_heading_too_far_above_stays_off_screen() {
let mut cursor = GridState::new();
cursor.select(7);
let mut grid = Grid::new(["name"]).heading("far").state(&cursor);
for i in 0..8 {
grid = grid.row([format!("r{i}")]);
}
let shown = drawn(10, 5, grid);
assert!(!shown.contains("far") && shown.contains("r7"), "{shown}");
}
#[test]
fn loading_false_takes_back_loading_but_not_an_error() {
let grid = Grid::new(["name"]).row(["core"]);
assert!(matches!(grid.loading(true).loading(false).body, Body::Rows));
let grid = Grid::new(["name"]).error("offline");
assert!(matches!(grid.loading(false).body, Body::Error(_)));
}
#[test]
fn loading_rows_shimmer_in_colour() {
let grid = Grid::new(["name", "status"]).loading(true);
let mut f = Frame::new(30, 6).at(0.5);
crate::style::with_color_mode(ColorMode::TrueColor, || f.render(f.area(), grid));
assert!(f.snapshot().plain().contains('━'));
}
#[test]
fn a_grid_one_row_tall_shows_just_its_header() {
let grid = Grid::new(["name", "status"]).row(["api", "up"]);
assert_eq!(drawn(4, 1, grid), " n");
}
#[test]
fn striped_rows_alternate() {
let cursor = GridState::new();
let grid = Grid::new(["n"])
.row(["a"])
.row(["b"])
.row(["c"])
.striped()
.state(&cursor);
let mut f = Frame::new(10, 5);
crate::style::with_color_mode(ColorMode::TrueColor, || f.render(f.area(), grid));
assert_ne!(f.snapshot().lines()[3], f.snapshot().lines()[4]);
}
}