summaryrefslogtreecommitdiff
path: root/test/e2e_harness.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/e2e_harness.zig')
-rw-r--r--test/e2e_harness.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig
index 26e942e7..f9ed44c0 100644
--- a/test/e2e_harness.zig
+++ b/test/e2e_harness.zig
@@ -20,6 +20,7 @@ extern "c" fn openpty(
winp: ?*const posix.winsize,
) c_int;
extern "c" fn ttyname(fd: c_int) ?[*:0]const u8;
+extern "c" fn ptsname(fd: c_int) ?[*:0]const u8;
extern "c" fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
extern "c" fn _exit(status: c_int) noreturn;
extern "c" fn unsetenv(name: [*:0]const u8) c_int;
@@ -251,6 +252,21 @@ pub const Harness = struct {
return if (n > 0) @intCast(n) else 0;
}
+ /// Bytes typed that the app has not read yet: its end's input queue
+ /// (the master's FIONREAD counts only what the app wrote).
+ pub fn unread(self: *Harness) usize {
+ const FIONREAD: c_int = switch (@import("builtin").os.tag) {
+ .linux => posix.T.FIONREAD,
+ else => 0x4004667f,
+ };
+ const fd = libc.open(ptsname(self.master) orelse return 0, .{ .ACCMODE = .RDWR, .NOCTTY = true, .CLOEXEC = true });
+ if (fd < 0) return 0;
+ defer _ = libc.close(fd);
+ var n: c_int = 0;
+ if (posix.system.ioctl(fd, FIONREAD, @intFromPtr(&n)) != 0) return 0;
+ return if (n > 0) @intCast(n) else 0;
+ }
+
/// Resize both the pty (SIGWINCH to the app) and our terminal (grid reflows
/// to the new size). Harness terminal first so it's ready for the app's
/// re-render at the new size.