╭──────────╮ │← previous│ ╰──────────╯ ╭ changed ────────╮ │src/main_wasm.zig│ ╰─────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │89 switch (child.focus.kind) { │ │90 .text_input, .text_input_password => _focusInput(@intCast(gid)), │ │91 + .custom => |custom| if (std.mem.eql(u8, custom, "submit")) _focusInput(@intCast(gid)),│ │92 else => {}, │ │93 } │ │94 } │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────╮ │114 │ │115 fn onMouseClick(focus_id: usize) !void { │ │116 const root_ptr = if (root) |*root_value| root_value else return error.NotStarted;│ │109 - const root_focus = root_ptr.getFocus(); │ │110 - try root_focus.setFocus(focus_id); │ │111 - // forward a left press into the widget tree for plain in-tree clickables │ │112 - if (root_focus.children.get(focus_id)) |child| { │ │113 - const r = child.rect; │ │114 - try root_ptr.input(allocator, .{ .mouse = .{ │ │115 - .x = r.x, │ │116 - .y = r.y, │ │117 - .action = .{ .press = .left }, │ │118 - } }, root_focus); │ │119 - } │ │117 + try root_ptr.getFocus().setFocus(focus_id); │ │118 } │ │119 │ │120 fn consoleLog(arg: []const u8) void { │ ╰──────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ────────╮ │src/serve_ssh.zig│ ╰─────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │38 }; │ │39 │ │40 fn runTuiSession(handler: *const SessionHandler, sess: *ssh.SessionCtx, pty: ssh.PtySize) !void { │ │41 + // runTui owns the terminal, whose deinit restores the client's screen and │ │42 + // runs as the function unwinds — so any error it returns leaves the TUI torn │ │43 + // down and we can surface the failure on the restored screen before exiting. │ │44 + runTui(handler, sess, pty) catch |err| { │ │45 + std.debug.print("ssh tui session failed: {s}\n", .{@errorName(err)}); │ │46 + var buf: [256]u8 = undefined; │ │47 + const msg = std.fmt.bufPrint(&buf, "haxy ssh: {s}\r\n", .{@errorName(err)}) catch "haxy ssh: internal error\r\n";│ │48 + sess.writeBytes(msg) catch {}; │ │49 + try sess.exit(1); │ │50 + return; │ │51 + }; │ │52 + try sess.exit(0); │ │53 +} │ │54 + │ │55 +fn runTui(handler: *const SessionHandler, sess: *ssh.SessionCtx, pty: ssh.PtySize) !void { │ │56 const allocator = sess.allocator; │ │57 const io = sess.io; │ │58 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ │ 78 │ │ 79 var root = try ui.initRoot(allocator, &page, &ui_session); │ │ 80 defer root.deinit(allocator); │ │ 81 + │ │ 82 + var session_writer_buf: [8192]u8 = undefined; │ │ 83 + var session_writer = ssh.SessionWriter.init(sess, &session_writer_buf); │ │ 84 + │ │ 85 + // the terminal's deinit writes leave-alt / show-cursor / disable-mouse and │ │ 86 + // flushes, restoring the client's screen. as a function-scoped defer it runs │ │ 87 + // before runTui returns — on the normal path and on any error — so the │ │ 88 + // caller can write to the client afterward (and sess.exit can close cleanly). │ │ 89 + var terminal = try StreamTerminal.init(allocator, &session_writer.interface, .{ │ │ 90 + .width = effective_pty.width_cells, │ │ 91 + .height = effective_pty.height_cells, │ │ 92 + }); │ │ 93 + defer terminal.deinit(); │ │ 94 │ │ 67 - // terminal and its writer adapter live in a nested block so the deinit │ │ 68 - // (which writes leave-alt / show-cursor / disable-mouse to the channel) │ │ 69 - // fires BEFORE sess.exit closes the channel. otherwise the client's │ │ 70 - // terminal is left in alt-screen mode after disconnect. │ │ 71 - { │ │ 72 - var session_writer_buf: [8192]u8 = undefined; │ │ 73 - var session_writer = ssh.SessionWriter.init(sess, &session_writer_buf); │ │ 95 + var last_size = Size{ .width = 0, .height = 0 }; │ │ 96 + var last_grid = try Grid.init(allocator, last_size); │ │ 97 + defer last_grid.deinit(); │ │ 98 + │ │ 99 + // initial render — user sees the page immediately │ │100 + try root.build(allocator, .{ │ │101 + .min_size = .{ .width = null, .height = null }, │ │102 + .max_size = .{ .width = last_size.width, .height = last_size.height }, │ │103 + }, root.getFocus()); │ │104 + _ = try terminal.render(&root, &last_grid, &last_size); │ │105 │ │ 75 - var terminal = try StreamTerminal.init(allocator, &session_writer.interface, .{ │ │ 76 - .width = effective_pty.width_cells, │ │ 77 - .height = effective_pty.height_cells, │ │ 78 - }); │ │ 79 - defer terminal.deinit(); │ │106 + // event loop. nextEvent blocks until something interesting arrives; │ │107 + // for each event, rebuild the widget tree and re-render so the user │ │108 + // sees the effect of their input on the same iteration. │ │109 + while (!terminal.shouldQuit()) { │ │110 + const event = try sess.nextEvent(); │ │111 + switch (event) { │ │112 + .data => |payload| { │ │113 + defer allocator.free(payload); │ │114 + try terminal.writeBytes(payload); │ │115 + while (terminal.popKey()) |key| { │ │116 + try ui.inputKey(allocator, &root, key, &terminal); │ │117 + } │ │118 + }, │ │119 + .resize => |sz| { │ │120 + terminal.pushResize(.{ .width = sz.width_cells, .height = sz.height_cells });│ │121 + while (terminal.popKey()) |key| { │ │122 + try ui.inputKey(allocator, &root, key, &terminal); │ │123 + } │ │124 + }, │ │125 + .close => terminal.requestQuit(), │ │126 + } │ │127 │ │ 81 - var last_size = Size{ .width = 0, .height = 0 }; │ │ 82 - var last_grid = try Grid.init(allocator, last_size); │ │ 83 - defer last_grid.deinit(); │ │128 + // apply any actions the widgets queued this frame, persisting those │ │129 + // that belong to a logged-in user │ │130 + try ui.Action.dispatchPending(repo_opts, io, allocator, &repo, &ui_session); │ │131 │ │ 85 - // initial render — user sees the page immediately │ │132 try root.build(allocator, .{ │ │133 .min_size = .{ .width = null, .height = null }, │ │134 .max_size = .{ .width = last_size.width, .height = last_size.height }, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │135 }, root.getFocus()); │ │136 _ = try terminal.render(&root, &last_grid, &last_size); │ │ 91 - │ │ 92 - // event loop. nextEvent blocks until something interesting arrives; │ │ 93 - // for each event, rebuild the widget tree and re-render so the user │ │ 94 - // sees the effect of their input on the same iteration. │ │ 95 - while (!terminal.shouldQuit()) { │ │ 96 - const event = try sess.nextEvent(); │ │ 97 - switch (event) { │ │ 98 - .data => |payload| { │ │ 99 - defer allocator.free(payload); │ │100 - try terminal.writeBytes(payload); │ │101 - while (terminal.popKey()) |key| { │ │102 - try ui.inputKey(allocator, &root, key, &terminal); │ │103 - } │ │104 - }, │ │105 - .resize => |sz| { │ │106 - terminal.pushResize(.{ .width = sz.width_cells, .height = sz.height_cells });│ │107 - while (terminal.popKey()) |key| { │ │108 - try ui.inputKey(allocator, &root, key, &terminal); │ │109 - } │ │110 - }, │ │111 - .close => terminal.requestQuit(), │ │112 - } │ │113 - │ │114 - try root.build(allocator, .{ │ │115 - .min_size = .{ .width = null, .height = null }, │ │116 - .max_size = .{ .width = last_size.width, .height = last_size.height }, │ │117 - }, root.getFocus()); │ │118 - _ = try terminal.render(&root, &last_grid, &last_size); │ │119 - } │ │137 } │ │121 - │ │122 - try sess.exit(0); │ │138 } │ │139 │ │140 // --------------------------------------------------------------------------- │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ─────────╮ │src/test/event.zig│ ╰──────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │115 │ │116 { │ │117 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); │ │118 - │ │119 - const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │120 - │ │121 - // read the moment we just created │ │122 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │123 - const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); │ │124 - │ │125 - // get the last object id │ │126 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; │ │127 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │128 - _ = try last_object_id_cursor.readBytes(&last_object_id); │ │129 - │ │130 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │131 - const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); │ │132 - │ │133 - try std.testing.expectEqual(1, try haxy.count()); │ │118 │ │135 - const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; │ │136 - const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); │ │119 + const haxy_moment = try evt.currentMoment(repo_opts, &repo); │ │120 │ │138 - const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; │ │139 - const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); │ │140 - │ │121 // get the map of issues │ │122 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse return error.NotFound;│ │123 const event_id_to_issue = try Repo.DB.HashMap(.read_only).init(event_id_to_issue_cursor); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │150 }, │ │151 }, │ │152 }; │ │173 - │ │174 - { │ │175 - var json: std.Io.Writer.Allocating = .init(allocator); │ │176 - defer json.deinit(); │ │153 │ │178 - for (events_to_consume2) |event| { │ │179 - json.clearRetainingCapacity(); │ │154 + // commit and consume the new event │ │155 + try evt.commitAndConsume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }, &events_to_consume2); │ │156 │ │181 - try std.json.Stringify.value(event, .{}, &json.writer); │ │182 - │ │183 - // commit the event into a special branch │ │184 - _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, .{ .kind = .head, .name = "haxy/meta" }); │ │185 - } │ │186 - } │ │187 - │ │188 - // │ │189 - // consume events into the database │ │157 // │ │191 - │ │192 - { │ │193 - try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); │ │194 - │ │195 - const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │196 - │ │197 - // read the moment we just created │ │198 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │199 - const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); │ │200 - │ │201 - // get the last object id │ │202 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound;│ │203 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │204 - _ = try last_object_id_cursor.readBytes(&last_object_id); │ │205 - │ │206 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │207 - const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); │ │208 - │ │209 - try std.testing.expectEqual(2, try haxy.count()); │ │210 - } │ │211 - │ │212 - // │ │158 // rebase the branch so it no longer includes the edit event │ │159 // │ │160 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │196 │ │197 { │ │198 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); │ │254 - │ │255 - const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │199 │ │257 - // read the moment we just created │ │258 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │259 - const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); │ │200 + const haxy_moment = try evt.currentMoment(repo_opts, &repo); │ │201 │ │261 - // get the last object id │ │262 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; │ │263 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │264 - _ = try last_object_id_cursor.readBytes(&last_object_id); │ │265 - │ │266 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │267 - const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); │ │268 - │ │269 - try std.testing.expectEqual(2, try haxy.count()); │ │270 - │ │271 - const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; │ │272 - const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); │ │273 - │ │274 - const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; │ │275 - const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); │ │276 - │ │202 // get the map of issues │ │203 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse return error.NotFound;│ │204 const event_id_to_issue = try Repo.DB.HashMap(.read_only).init(event_id_to_issue_cursor); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │255 │ │256 { │ │257 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); │ │333 - │ │334 - const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │335 - │ │336 - // read the moment we just created │ │337 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │338 - const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); │ │339 - │ │340 - // get the last object id │ │341 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; │ │342 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │343 - _ = try last_object_id_cursor.readBytes(&last_object_id); │ │344 - │ │345 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │346 - const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); │ │347 - │ │348 - try std.testing.expectEqual(1, try haxy.count()); │ │349 - │ │350 - const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; │ │351 - const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); │ │258 │ │353 - const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; │ │354 - const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); │ │259 + const haxy_moment = try evt.currentMoment(repo_opts, &repo); │ │260 │ │261 // get the map of issues │ │262 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse return error.NotFound;│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │365 │ │366 { │ │367 try evt.consume(repo_opts, io, allocator, &repo, .{ .kind = .head, .name = "haxy/meta" }); │ │463 - │ │464 - const history = try Repo.DB.ArrayList(.read_only).init(repo.core.db.rootCursor().readOnly()); │ │465 - │ │466 - // read the moment we just created │ │467 - const moment_cursor = try history.getCursor(-1) orelse return error.NotFound; │ │468 - const moment = try Repo.DB.HashMap(.read_only).init(moment_cursor); │ │469 - │ │470 - // get the last object id │ │471 - const last_object_id_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy-last-object-id")) orelse return error.NotFound; │ │472 - var last_object_id: [hash.byteLen(repo_opts.hash)]u8 = undefined; │ │473 - _ = try last_object_id_cursor.readBytes(&last_object_id); │ │474 - │ │475 - const haxy_cursor = try moment.getCursor(hash.hashInt(repo_opts.hash, "haxy")) orelse return error.NotFound; │ │476 - const haxy = try Repo.DB.ArrayList(.read_only).init(haxy_cursor); │ │477 - │ │478 - try std.testing.expectEqual(1, try haxy.count()); │ │368 │ │480 - const haxy_moments_cursor = try haxy.getCursor(-1) orelse return error.NotFound; │ │481 - const haxy_moments = try Repo.DB.HashMap(.read_only).init(haxy_moments_cursor); │ │369 + const haxy_moment = try evt.currentMoment(repo_opts, &repo); │ │370 │ │483 - const haxy_moment_cursor = try haxy_moments.getCursor(hash.bytesToInt(repo_opts.hash, &last_object_id)) orelse return error.NotFound; │ │484 - const haxy_moment = try Repo.DB.HashMap(.read_only).init(haxy_moment_cursor); │ │485 - │ │371 // get the map of issues │ │372 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, "event-id->issue")) orelse return error.NotFound;│ │373 const event_id_to_issue = try Repo.DB.HashMap(.read_only).init(event_id_to_issue_cursor); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯