| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
use crate::{Grid, Identity}; |
| 9 |
use shop_vt::Parser; |
| 10 |
|
| 11 |
|
| 12 |
pub(crate) fn feed(grid: &mut Grid, bytes: &[u8]) { |
| 13 |
let mut p = Parser::new(); |
| 14 |
p.advance(grid, bytes); |
| 15 |
} |
| 16 |
|
| 17 |
pub(crate) fn row_str(grid: &Grid, r: u16) -> String { |
| 18 |
grid.row(r) |
| 19 |
.iter() |
| 20 |
.map(crate::Cell::c) |
| 21 |
.collect::<String>() |
| 22 |
.trim_end() |
| 23 |
.to_string() |
| 24 |
} |
| 25 |
|
| 26 |
pub(crate) fn assert_cursor(grid: &Grid, row: u16, col: u16) { |
| 27 |
let c = grid.cursor(); |
| 28 |
assert_eq!( |
| 29 |
(c.row, c.col), |
| 30 |
(row, col), |
| 31 |
"cursor mismatch (wrap_next={})", |
| 32 |
c.wrap_next |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
pub(crate) fn identified() -> Grid { |
| 37 |
let mut g = Grid::new(80, 24); |
| 38 |
g.set_identity(Identity { |
| 39 |
name: "shop".into(), |
| 40 |
version: "1.2.3".into(), |
| 41 |
cell_px: (9, 20), |
| 42 |
fg: [0xe6, 0xde, 0xd3], |
| 43 |
bg: [0x25, 0x23, 0x1f], |
| 44 |
}); |
| 45 |
g |
| 46 |
} |
| 47 |
|
| 48 |
pub(crate) fn reply_to(g: &mut Grid, bytes: &[u8]) -> String { |
| 49 |
feed(g, bytes); |
| 50 |
String::from_utf8(g.take_pending_replies()).unwrap() |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
pub(crate) fn history_text(g: &Grid) -> String { |
| 57 |
g.text_range(0, g.history_len()) |
| 58 |
} |
| 59 |
|