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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
//! docs/typ/guide.typ, Modes <modes>.
const std = @import("std");
const Session = @import("session").Session;
const expectEqual = std.testing.expectEqual;
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 "modes: Esc in normal mode alternates between two panes of the same kind" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" });
var dir: [4096]u8 = undefined;
const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
var s = try Session.initFile(std.testing.allocator, "a\n");
defer s.deinit();
const a = try s.focused();
try s.write("/look", s.at("{s}/b.txt\n", .{at}));
const b = try s.focused();
try std.testing.expect(a != b);
for (0..6) |_| {
const was = try s.focused();
try s.keys("\x1b");
try expectEqual(if (was == a) b else a, try s.focused());
}
}
test "modes: Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
_ = try s.newPane();
for ([_][]const u8{ "New Tty", "Newcol" }) |tag| {
const was = try s.focused();
// A click types into the tag; Esc is normal mode there, the next
// one is out of it.
try s.click(tag, 0, 1);
try s.keys("\x1b");
try s.expect("/focus", "");
try s.keys("\x1b");
try std.testing.expect(was != try s.focused());
}
}
test "modes: Shift-Esc backs out to the previous pane in every mode, never into raw" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
const doc = try s.focused();
try s.keys("\u{F015}n"); // a shell under the doc
const shell = try s.focused();
if (std.mem.eql(u8, try mode(&s, shell), "tty")) try s.keys("\x02");
try std.testing.expectEqualStrings("normal", try mode(&s, shell));
// A terminal in normal mode: out, still normal, never raw.
try s.keys("\u{F016}\x1b");
try expectEqual(doc, try s.focused());
try std.testing.expectEqualStrings("normal", try mode(&s, shell));
// A text pane in insert mode: out of insert, and out of the pane.
try s.keys("i");
try std.testing.expectEqualStrings("insert", try mode(&s, doc));
try s.keys("\u{F016}\x1b");
try std.testing.expectEqualStrings("normal", try mode(&s, doc));
try std.testing.expect(doc != try s.focused());
}
|