summaryrefslogtreecommitdiff
path: root/test/behaviour/terminals.zig
blob: f6bbdfa0655f5f4f336ce050a1aa6b3d0b0ae60c (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! docs/typ/guide.typ, Terminals <terminals>.
const std = @import("std");
const Session = @import("session").Session;

fn mode(s: *Session, pane: u32) ![]const u8 {
    const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane}));
    const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len;
    return std.mem.trimEnd(u8, ctl[at..], " ");
}

test "terminals: Togglettymode and Ctrl-B share the mode's transitions, from the body or its tag, and a text pane refuses it" {
    var s = try Session.initTerm(std.testing.allocator);
    defer s.deinit();
    const n = try s.focused();
    const ctl = s.at("/pane/{d}/ctl", .{n});
    try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/tag", .{n})), " Mode ") != null);
    try s.write(s.at("/pane/{d}/tag", .{n}), " Togglettymode");
    try std.testing.expectEqualStrings("tty", try mode(&s, n));
    try s.write(ctl, "Togglettymode\n");
    try std.testing.expectEqualStrings("normal", try mode(&s, n));
    try s.keys("\x02");
    try std.testing.expectEqualStrings("tty", try mode(&s, n));
    // The tag has its own mode: the body keeps tty while the tag is typed
    // into, and either way of toggling gives the body the keyboard back.
    const tag_row = (try s.where("Togglettymode"))[1];
    try s.click("Togglettymode", 0, 1);
    try std.testing.expectEqualStrings("tty", try mode(&s, n));
    try std.testing.expectEqual(tag_row, (try s.cursor()).?[1]);
    try s.write(ctl, "Togglettymode\n");
    try std.testing.expectEqualStrings("normal", try mode(&s, n));
    try std.testing.expect((try s.cursor()).?[1] > tag_row);
    try s.click("Togglettymode", 0, 1);
    try s.keys("\x02");
    try std.testing.expectEqualStrings("tty", try mode(&s, n));
    try std.testing.expect((try s.cursor()).?[1] > tag_row);
    // A middle click on the word in the tag.
    try s.click("Togglettymode", 0, 2);
    try std.testing.expectEqualStrings("normal", try mode(&s, n));
    // A text pane refuses it, normal, its text as it was.
    const file = try s.newPane();
    try s.write(s.at("/pane/{d}/body", .{file}), "unchanged\n");
    _ = try s.refused(s.at("/pane/{d}/ctl", .{file}), "Togglettymode\n");
    try std.testing.expectEqualStrings("Togglettymode: only a terminal pane takes it", s.said);
    try std.testing.expectEqualStrings("normal", try mode(&s, file));
    try s.expect(s.at("/pane/{d}/body", .{file}), "unchanged\n");
}