diff options
Diffstat (limited to 'test/session.zig')
| -rw-r--r-- | test/session.zig | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig index 16a131fd..f572a4b1 100644 --- a/test/session.zig +++ b/test/session.zig @@ -314,6 +314,35 @@ pub const Session = struct { var it = std.mem.splitScalar(u8, tag[lo + 2 .. close], '/'); return .{ try std.fmt.parseInt(u32, it.next().?, 10), try std.fmt.parseInt(u32, it.next() orelse return error.NoPage, 10) }; } + + // pane2: + + /// Each cell's style as /screen draws it, as JSON text (compare two + /// cells by it), row-major as `screen` draws the cells: row `y`'s cell + /// `x` is `[y * cols + x]`. + pub fn styles(s: *Session) ![]const []const u8 { + const a = s.arena.allocator(); + const json = try std.json.parseFromSliceLeaky(std.json.Value, a, try s.read("/screen"), .{}); + const kinds = json.object.get("styles").?.array.items; + const named = try a.alloc([]const u8, kinds.len); + for (kinds, named) |style, *text| text.* = try std.json.Stringify.valueAlloc(a, style, .{}); + const cells = json.object.get("cells").?.array.items; + const out = try a.alloc([]const u8, cells.len); + for (cells, out) |cell, *style| style.* = named[@intCast(cell.array.items[1].integer)]; + return out; + } + + // core2: + + /// The background /screen draws at a cell, as its JSON (`{"rgb":[255,255,255]}`). + pub fn bg(s: *Session, col: usize, row: usize) ![]const u8 { + const a = s.arena.allocator(); + const json = try std.json.parseFromSliceLeaky(std.json.Value, a, try s.read("/screen"), .{}); + const cols: usize = @intCast(json.object.get("cols").?.integer); + const cell = json.object.get("cells").?.array.items[row * cols + col]; + const style = json.object.get("styles").?.array.items[@intCast(cell.array.items[1].integer)]; + return std.json.Stringify.valueAlloc(a, style.object.get("bg").?, .{}); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { |
