//! docs/typ/reference.typ, Panes . const std = @import("std"); const Session = @import("session").Session; test "panes: a collapsed pane's ctl says so" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const first = try s.focused(); _ = try s.newPane(); try s.write(s.at("/pane/{d}/ctl", .{first}), "Collapse\n"); try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " collapsed ") != null); } test "panes: a pane's ctl read ends with its mode, as its tag's box shows it" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const ctl = s.at("/pane/{d}/ctl", .{try s.focused()}); try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:normal ")); try s.keys("i"); try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:insert ")); try s.keys("\x1bv"); try std.testing.expect(std.mem.endsWith(u8, try s.read(ctl), " mode:select ")); } test "panes: the ctl word name refuses a leading blank, as the name file does" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const ctl = s.at("/pane/{d}/ctl", .{try s.focused()}); try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "name /tmp/lead.txt\n")); try std.testing.expectEqualStrings("bad character in file name: a blank at its start", s.said); try s.write(ctl, "name /tmp/ok.txt\n"); try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), "/tmp/ok.txt\n"); } test "panes: Putall saves every pane with unsaved edits to a file, one each, and leaves the rest" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "clean.txt", .data = "clean\n" }); var dir_buf: [4096]u8 = undefined; const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const first = try s.focused(); try s.write(s.at("/pane/{d}/name", .{first}), "/tmp/pardes-putall-a.txt\n"); try s.write(s.at("/pane/{d}/body", .{first}), "edited\n"); // A file opened from disk, unedited. try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/clean.txt\n", .{dir})); try std.testing.expectEqual(@as(usize, 0), s.saved); try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } fn has(hay: []const u8, needle: []const u8) bool { return std.mem.indexOf(u8, hay, needle) != null; } test "panes: focus reads the pane with the keyboard, and a serial written to it moves the keyboard there, and only that" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); const first = try s.focused(); const second = try s.newPane(); try s.expect("/focus", s.at("{d}\n", .{second})); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{first})), " notcurrent ")); // A column's tag has the keyboard: no pane does, and a write takes it back. try s.write("/ctl", "Newcol\n"); try s.expect("/focus", ""); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " notcurrent ")); try s.write("/focus", s.at("{d}\n", .{first})); try s.expect("/focus", s.at("{d}\n", .{first})); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{first})), " current ")); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " notcurrent ")); try std.testing.expectEqual(@as(u16, 2), try s.refused("/focus", "99999\n")); try std.testing.expectEqualStrings("no such pane", s.said); for ([_][]const u8{ "", "two", "-1", "1 2" }) |bad| try std.testing.expectEqual(@as(u16, 22), try s.refused("/focus", bad)); try s.expect("/focus", s.at("{d}\n", .{first})); // Focus gives the keyboard only: a folded pane stays folded. try s.write(s.at("/pane/{d}/ctl", .{second}), "Collapse\n"); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " collapsed ")); try s.write("/focus", s.at("{d}", .{second})); try s.expect("/focus", s.at("{d}\n", .{second})); try std.testing.expect(has(try s.read(s.at("/pane/{d}/ctl", .{second})), " collapsed ")); } test "panes: the pane ctl takes acme's verbs and the pane's builtins, and refuses the rest in Plan 9's words" { var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); defer s.deinit(); const n = try s.focused(); const ctl = s.at("/pane/{d}/ctl", .{n}); // A builtin is its own capitalised word: `GET` and `DEL` are none. for ([_][]const u8{ "lock x", "bogus", "DEL", "GET", "get x", "look /tmp", "exec Del" }) |bad| { try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, s.at("{s}\n", .{bad}))); try std.testing.expectEqualStrings(s.at("unknown control message \"{s}\"", .{std.mem.sliceTo(bad, ' ')}), s.said); } _ = try s.refused(ctl, "Newcol\n"); try std.testing.expectEqualStrings("not a window control message \"Newcol\": write it to /ctl", s.said); _ = try s.refused(ctl, "Verbose off\n"); try std.testing.expectEqualStrings("not a window control message \"Verbose\": write it to /ctl", s.said); _ = try s.refused(ctl, "Collapse now\n"); try std.testing.expectEqualStrings("wrong #args in control message \"Collapse\"", s.said); // Checked whole first: a bad line anywhere and nothing ran. try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "Msg first\nbogus\n")); // A pane's builtin runs at that pane. try s.write(ctl, "Msg from ctl\n"); try std.testing.expect(has(try s.read("/log"), s.at("msg {d} from ctl\n", .{n}))); // One that means nothing bare is refused before anything runs. _ = try s.refused(ctl, "Find\n"); try std.testing.expectEqualStrings("wrong #args in control message \"Find\"", s.said); try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "Msg first\nMsg\n")); try std.testing.expect(!has(try s.read("/log"), "first")); // Save with no name on a scratch would ask for one: refused, not asked. const other = try s.newPane(); _ = try s.refused(s.at("/pane/{d}/ctl", .{other}), "Save\n"); try std.testing.expectEqualStrings("control message needs its argument \"Save\"", s.said); // A line after the one that closed the pane has nowhere to run. try std.testing.expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/ctl", .{other}), "Del\nMsg after\n")); try std.testing.expectError(error.Refused, s.read(s.at("/pane/{d}/ctl", .{other}))); }