diff options
Diffstat (limited to 'test/session.zig')
| -rw-r--r-- | test/session.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig index b55987eb..f3d96918 100644 --- a/test/session.zig +++ b/test/session.zig @@ -188,6 +188,24 @@ pub const Session = struct { pub fn where(s: *Session, text: []const u8) !struct { usize, usize } { return s.find(text); } + + /// The cell the screen's cursor is drawn on, its column and row. + pub fn cursor(s: *Session) !struct { usize, usize } { + const json = try std.json.parseFromSliceLeaky(std.json.Value, s.arena.allocator(), try s.read("/screen"), .{}); + const c = json.object.get("cursor").?; + if (c != .object) return error.NoCursor; + return .{ @intCast(c.object.get("x").?.integer), @intCast(c.object.get("y").?.integer) }; + } + + /// `data` written to `path` truncated first, as a shell's `>` does. + pub fn replace(s: *Session, path: []const u8, data: []const u8) !void { + const node, const h = try s.open(path, 1); + defer _ = s.serve(.{ .tag = 0, .op = .release, .node = node, .handle = h, .opened = true }); + const t = s.serve(.{ .tag = 0, .op = .setattr, .node = node, .handle = h, .truncate = true }); + if (t.status != .ok) return refusal(path, t); + const w = s.serve(.{ .tag = 0, .op = .write, .node = node, .handle = h, .data = data }); + if (w.status != .ok) return refusal(path, w); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { |
