From d1273bbd99daf9b1855d82bf315db8ede20abde5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 16:52:58 -0300 Subject: fs: a pane's ctl read ends with its mode (mode:normal|insert|select|tty, select being normal mode extending), and kbdin takes Plan 9's Kalt, Kshift and Kctl runes (U+F015-F017), each adding its modifier to the key after it, an Alt or Ctrl key typing no text: the two surfaces the behavioural tests' inventory found most wanted (90 tests read body.mode, 18 send Alt or Shift); the tests that pinned the ctl line's end look for its words instead Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- docs/typ/reference.typ | 10 +++++++--- src/CHANGELOG.md | 2 ++ src/ninep/ctl.zig | 38 ++++++++++++++++++++++++++++++-------- src/pardes.zig | 2 +- test/behaviour/other_files.zig | 7 +++++++ test/behaviour/panes.zig | 13 ++++++++++++- test/fs.py | 4 ++-- test/pdf.zig | 2 +- test/record_demos.py | 5 +++-- 9 files changed, 65 insertions(+), 18 deletions(-) diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 75b33151..45863f04 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -593,8 +593,10 @@ while a column or workspace tag has the keyboard. *Pane ctl.* Reading it gives acme's status line: serial, tag length, body length, isdir (1 for a directory pane, else 0), dirty, width in cells, font, tab width, undo available, redo available, then `current`/`notcurrent`, a REPL's id if bound, -`collapsed` when it is, and for a PDF `fit:width|height -tint:disabled|filtered|full`. Each field ends in a blank and the line has +`collapsed` when it is, for a PDF `fit:width|height +tint:disabled|filtered|full`, and last the body's mode, +`mode:normal|insert|select|tty` (select: normal mode extending, helix's +#key("v")). Each field ends in a blank and the line has no newline, as acme's has none (`cat ctl; echo`). It takes: @@ -916,7 +918,9 @@ at 200, ending in `…`. Control characters become spaces. Backspace, `0x7f` Delete, `0x1b` #key("Esc"), and the arrows, Home, End, Page Up and Down, Insert and F1-F12 at their private-use runes (`U+F00E` up, `U+F800` down, `U+F011` left, `U+F012` - right, `U+F00D` Home, `U+F018` End). No Alt, Shift or Super. + right, `U+F00D` Home, `U+F018` End). Its Kalt, Kshift and Kctl + (`U+F015`, `U+F016`, `U+F017`) add Alt, Shift or Ctrl to the key after + them: `U+F015` `x` is Alt-x. No Super. - #file("/mousein") (write only), devmouse's, in cells: a line `m col row buttons` is the mouse as it now is, the buttons Plan 9's bits (1 left, 2 middle, 4 right; 8 and 16 a wheel notch up and down). What changed since diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index aa304597..7a46555c 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -20,6 +20,8 @@ does, each write done before it is answered, so the read that checks it needs no sleep. test/fs.py's keys_and_mouse finds where to click on /screen. +- A pane's `ctl` read ends with its mode, `mode:normal|insert|select|tty`, + and `kbdin` takes Plan 9's Kalt, Kshift and Kctl runes before a key. - One `pardes --daemon` per user keeps sessions, started by the first session and gone once it keeps nothing. `pardes` in a terminal forks its session off and stays as its stub: `Detach` (`SPC s D`), or a diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 4a3d753c..cc300476 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -416,7 +416,7 @@ fn writeQuoted(w: *std.Io.Writer, s: []const u8) !void { try w.writeByte('\''); } -pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "collapsed fit:height tint:filtered ".len; +pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "collapsed fit:height tint:filtered mode:insert ".len; /// acme's winctlprint (plan9port wind.c), field for field: serial, tag /// length, body length, isdir (1 for a directory pane), the dirty flag, @@ -452,6 +452,9 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { // PdfTint, in the words they take. if (pane.collapsed) w.writeAll("collapsed ") catch {}; if (comptime pardes.pdf_enabled) if (pane.pdf) |pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; + // Last, the body's mode, which the tag shows as a box: helix's select + // is normal mode extending. + w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch {}; return w.buffered(); } @@ -997,11 +1000,30 @@ const e_no_pane = "no such pane"; /// and all before the write is answered. Control runes are Ctrl and a /// letter, but for Plan 9's keys (include/ALL/keyboard.h): \n or \r Enter, /// \t Tab, \b Backspace, 0x7f Delete, 0x1b Esc, and the arrows, Home, End, -/// Page Up and Down, Insert and F1-F12 at its private-use runes. +/// Page Up and Down, Insert and F1-F12 at its private-use runes. Its +/// Kalt, Kshift and Kctl runes, which Plan 9 sends alone, add Alt, Shift +/// or Ctrl to the key after them. pub fn writeKbdin(p: *Pardes, req: Req) Reply { const view = std.unicode.Utf8View.init(req.data) catch return tree.failText(req.tag, E.INVAL, "invalid UTF-8"); var it = view.iterator(); - while (it.nextCodepointSlice()) |rune| p.update(.{ .key = kbdKey(rune) }); + var mods: pardes.Key = .{ .cp = 0 }; + while (it.nextCodepointSlice()) |rune| { + switch (std.unicode.utf8Decode(rune) catch unreachable) { + 0xF015 => mods.alt = true, + 0xF016 => mods.shift = true, + 0xF017 => mods.ctrl = true, + else => { + var key = kbdKey(rune); + key.alt = key.alt or mods.alt; + key.shift = key.shift or mods.shift; + key.ctrl = key.ctrl or mods.ctrl; + // A modified key types no text, as a terminal's report has none. + if (mods.alt or mods.ctrl) key.text = ""; + p.update(.{ .key = key }); + mods = .{ .cp = 0 }; + }, + } + } return .{ .tag = req.tag, .written = @intCast(req.data.len) }; } @@ -1419,7 +1441,7 @@ test "pane ctl read is acme's fields -- index's five, width in cells, font, tab try testing.expectEqual(Status.ok, a.reply.status); var want: std.ArrayList(u8) = .empty; defer want.deinit(gpa); - try want.print(gpa, "{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {s} {d:>11} {d:>11} {d:>11} current ", .{ + try want.print(gpa, "{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {s} {d:>11} {d:>11} {d:>11} current mode:normal ", .{ pane.serial, pane_files.tagOf(p, pane).len, @as(usize, 2), 0, 0, pane.cols, "default", config.tab_now, 0, 0, }); try testing.expectEqualStrings(want.items, a.bytes); @@ -1490,18 +1512,18 @@ test "focus reads the pane with the keyboard, and a serial written to it moves t var line: [16]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{second}), rd(p, focus, 0, 64).bytes); try testing.expectEqual(@as(u64, rd(p, focus, 0, 64).bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size); - try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " notcurrent ")); + try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " notcurrent ") != null); // A header has the keyboard: no pane does, and a write takes it back. tagline.enterHeader(p, null); try testing.expectEqualStrings("", rd(p, focus, 0, 64).bytes); try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size); - try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ")); + try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ") != null); try testing.expectEqual(Status.ok, wr(p, focus, try std.fmt.bufPrint(&line, "{d}\n", .{first})).reply.status); try testing.expect(!p.header_focus); try testing.expectEqual(p.paneBySerial(first).?, p.active); - try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " current ")); - try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ")); + try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " current ") != null); + try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ") != null); try testing.expectEqualStrings(e_no_pane, wr(p, focus, "99999\n").reply.ename); try testing.expectEqual(E.NOENT, wr(p, focus, "99999").errno()); diff --git a/src/pardes.zig b/src/pardes.zig index fb3dc36f..ff64cb9f 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -1711,7 +1711,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe try std.testing.expect(ran.pty_len == 0 and ran.spawned); // The pane's ctl line ends with the id it is bound as. var line: [ctlfs.ctl.pane_text_cap]u8 = undefined; - try std.testing.expect(std.mem.endsWith(u8, ctlfs.ctl.paneText(p, p.panes[1].?, &line), " python-a ")); + try std.testing.expect(std.mem.indexOf(u8, ctlfs.ctl.paneText(p, p.panes[1].?, &line), " python-a ") != null); } // What is sent is plain text: CRLF is LF, no ESC or other control. _ = exec.executeFrom(p, 0, "a = 1\r\nb = \x1b[201~2", true); diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index b97affc4..c0f9c08f 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -21,3 +21,10 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks, try std.testing.expectEqual(@as(u16, 22), try s.refused("/kbdin", "\xff")); try std.testing.expectError(error.Refused, s.read("/kbdin")); } + +test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Alt key types nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.keys("i\u{F015}zy\x1b"); + try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n"); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 45b7152c..01820a07 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -8,7 +8,18 @@ test "panes: a collapsed pane's ctl says so" { 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.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " collapsed ")); + 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" { diff --git a/test/fs.py b/test/fs.py index bd5ab501..5690cedc 100644 --- a/test/fs.py +++ b/test/fs.py @@ -267,8 +267,8 @@ def discovery(binary, embedded=False): # wctl `current` does; a pane's ctl line ends saying which it is. client.write('/focus', f'{first}\n'.encode()) assert client.read('/focus') == f'{first}\n'.encode() - assert client.read(f'/pane/{first}/ctl').endswith(b' current ') - assert client.read(f'/pane/{second}/ctl').endswith(b' notcurrent ') + assert b' current ' in client.read(f'/pane/{first}/ctl') + assert b' notcurrent ' in client.read(f'/pane/{second}/ctl') try: client.write('/focus', b'99999\n') raise AssertionError('focus took a serial no pane has') diff --git a/test/pdf.zig b/test/pdf.zig index 3bb751e2..fca0c240 100644 --- a/test/pdf.zig +++ b/test/pdf.zig @@ -2418,7 +2418,7 @@ test "a PDF's fit and tint, and Collapse, read in its ctl and come back from a D const ctlfs = pardes.ctlfs; const ctl_node = ctlfs.Node.of(doc.serial, .ctl); const read = p.fsPayload(p.serveFs(.{ .tag = 1, .op = .read, .node = ctl_node, .size = 4096 })); - try std.testing.expect(std.mem.endsWith(u8, read, "fit:height tint:full ")); + try std.testing.expect(std.mem.indexOf(u8, read, "fit:height tint:full ") != null); try pardes.dump.dumpState(p); const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); defer restored.deinit(); diff --git a/test/record_demos.py b/test/record_demos.py index 3c64f55c..a2e48d73 100644 --- a/test/record_demos.py +++ b/test/record_demos.py @@ -819,8 +819,9 @@ def pdf_tint_fit(s): s.pointer = s.cell_px(44, 12) s.shot(1.2) for _ in range(3): - before = s.read('/pane/1/ctl').split()[-1] - s.click(2, *pdf_tag(s, 'PdfTint'), done=lambda: s.read('/pane/1/ctl').split()[-1] != before, + tint = lambda: next(w for w in s.read('/pane/1/ctl').split() if w.startswith(b'tint:')) + before = tint() + s.click(2, *pdf_tag(s, 'PdfTint'), done=lambda: tint() != before, what='the tint', after=1.0) for fit in ('height', 'width'): s.click(2, *pdf_tag(s, 'PdfFit'), done=lambda: f'fit:{fit}' in s.read('/pane/1/ctl'), what='the fit', -- cgit v1.3