summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 16:52:58 -0300
committerGabriel Schneider <[email protected]>2026-11-03 16:52:58 -0300
commitd1273bbd99daf9b1855d82bf315db8ede20abde5 (patch)
tree14891fab4f951767dcf4d2b14470703055479b90 /src/ninep/ctl.zig
parenta0320c49c1288e8e74f18983f18988a024952bb8 (diff)
downloadpardes-d1273bbd99daf9b1855d82bf315db8ede20abde5.tar.gz
pardes-d1273bbd99daf9b1855d82bf315db8ede20abde5.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig38
1 files changed, 30 insertions, 8 deletions
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());