1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MIT OR Apache-2.0
//! 2026-09-26: Shared `TestBackend` helpers for the render tests: `screen`
//! draws the whole dashboard, `draw_into` one closure; both return one
//! trailing-trimmed `String` per row.
//!
//! Owner: server tui.
//! Invariants: none beyond the types.
use ratatui::Terminal;
use ratatui::backend::TestBackend;
use crate::tui::app::App;
/// 2026-09-26: `render::draw` at `w`×`h`, one `String` per row, trailing
/// blanks trimmed.
pub(super) fn screen(app: &App, w: u16, h: u16) -> Vec<String> {
let mut terminal = Terminal::new(TestBackend::new(w, h)).expect("backend");
terminal
.draw(|f| crate::tui::render::draw(f, app))
.expect("draw");
let buf = terminal.backend().buffer();
(0..h)
.map(|y| {
(0..w)
.map(|x| buf[(x, y)].symbol())
.collect::<String>()
.trim_end()
.to_string()
})
.collect()
}
pub(super) fn has(rows: &[String], needle: &str) -> bool {
rows.iter().any(|r| r.contains(needle))
}
/// 2026-09-26: Render one closure over the whole `w`×`h` area, for helpers
/// that take a `Rect` rather than an `App`. Rows as in [`screen`].
pub(super) fn draw_into(
w: u16,
h: u16,
f: impl FnOnce(&mut ratatui::Frame, ratatui::layout::Rect),
) -> Vec<String> {
let mut terminal = Terminal::new(TestBackend::new(w, h)).expect("backend");
terminal
.draw(|frame| {
let area = frame.area();
f(frame, area);
})
.expect("draw");
let buf = terminal.backend().buffer();
(0..h)
.map(|y| {
(0..w)
.map(|x| buf[(x, y)].symbol())
.collect::<String>()
.trim_end()
.to_string()
})
.collect()
}