diff options
Diffstat (limited to 'test/session.zig')
| -rw-r--r-- | test/session.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig index 8b3c5c41..c4ed0db2 100644 --- a/test/session.zig +++ b/test/session.zig @@ -182,6 +182,34 @@ pub const Session = struct { fn pardesOf(s: *Session) *Pardes { return @ptrCast(@alignCast(s.core)); } + + // core: + + /// /layout as its columns, left to right, `column:pane,pane` each and + /// a blank between (`1:2,5 3:`, column 3 empty). + pub fn columns(s: *Session) ![]const u8 { + const a = s.arena.allocator(); + var out: std.ArrayList(u8) = .empty; + var lines = std.mem.tokenizeScalar(u8, try s.read("/layout"), '\n'); + while (lines.next()) |line| { + if (std.mem.startsWith(u8, line, "active ")) continue; + var words = std.mem.tokenizeScalar(u8, line, ' '); + if (out.items.len > 0) try out.append(a, ' '); + try out.print(a, "{s}:", .{words.next().?}); + for (0..5) |_| _ = words.next(); // index x width current empty|full + var sep: []const u8 = ""; + while (words.next()) |pane| : (sep = ",") try out.print(a, "{s}{s}", .{ sep, pane }); + } + return out.items; + } + + /// The serial of the `i`th column from the left. + pub fn column(s: *Session, i: usize) !u32 { + var cols = std.mem.tokenizeScalar(u8, try s.columns(), ' '); + for (0..i) |_| _ = cols.next(); + const col = cols.next() orelse return error.NoColumn; + return std.fmt.parseInt(u32, col[0..std.mem.indexOfScalar(u8, col, ':').?], 10); + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { |
