1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
//! docs/typ/reference.typ, The root ctl <root-ctl>.
const std = @import("std");
const Session = @import("session").Session;
/// The screen's size, as /screen draws it.
fn size(s: *Session) !struct { usize, usize } {
const screen = try s.screen();
const cols = try std.unicode.utf8CountCodepoints(screen[0 .. std.mem.indexOfScalar(u8, screen, '\n') orelse screen.len]);
return .{ cols, std.mem.count(u8, screen, "\n") + 1 };
}
test "root-ctl: size sets the screen of a session no frontend is attached to, and only of one" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120 40\n")); // a frontend's
s.detach();
try s.write("/ctl", "size 120 40\n");
try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size 120\n"));
try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "size\n"));
_ = try s.refused("/ctl", "size 5 2\n");
try std.testing.expect(std.mem.indexOf(u8, s.said, "at least 20x6, at most 4096x4096") != null);
// The bad value quoted, never the word size.
try std.testing.expect(std.mem.endsWith(u8, s.said, "\"5 2\""));
// Too small for the panes it has, each its tag and two rows: refused,
// the size as it was.
for (0..4) |_| _ = try s.newPane();
_ = try s.refused("/ctl", "size 80 8\n");
try std.testing.expect(std.mem.indexOf(u8, s.said, "too small for the panes") != null);
try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
}
|