╭ changed ────────╮ │src/serve_ssh.zig│ ╰─────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │74 defer repo.deinit(io, allocator); │ │75 var ui_session = try ui.Session.init(&page_arena, &repo, .{}); │ │76 │ │77 - const page: ui.Page = .{ .home = try .init(&page_arena, ui_session.haxy_moment orelse unreachable) }; │ │77 + const page: ui.Page = try ui.Page.init(&page_arena, ui_session.haxy_moment orelse unreachable, ui_session.data.current_page);│ │78 │ │79 - var root = try ui.initRoot(allocator, &page, &ui_session); │ │80 - defer root.deinit(allocator); │ │79 + var nav = try ui.Nav.init(allocator, &page, &ui_session); │ │80 + defer nav.deinit(allocator); │ │81 │ │82 var session_writer_buf: [8192]u8 = undefined; │ │83 var session_writer = ssh.SessionWriter.init(sess, &session_writer_buf); │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │ 97 defer last_grid.deinit(); │ │ 98 │ │ 99 // initial render — user sees the page immediately │ │100 - try root.build(allocator, .{ │ │100 + try nav.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); │ │103 + }, nav.root.getFocus()); │ │104 + _ = try terminal.render(&nav.root, &last_grid, &last_size); │ │105 │ │106 // event loop. nextEvent blocks until something interesting arrives; │ │107 // for each event, rebuild the widget tree and re-render so the user │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────╮ │113 defer allocator.free(payload); │ │114 try terminal.writeBytes(payload); │ │115 while (terminal.popKey()) |key| { │ │116 - try ui.inputKey(allocator, &root, key, &terminal); │ │116 + try ui.inputKey(allocator, &nav.root, key, &ui_session);│ │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); │ │122 + try ui.inputKey(allocator, &nav.root, key, &ui_session); │ │123 } │ │124 }, │ │125 .close => terminal.requestQuit(), │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────╮ │127 │ │128 try ui_session.applyAndWritePending(io, allocator, &repo); │ │129 │ │130 - try root.build(allocator, .{ │ │130 + // reconcile navigation: forward to a new page, or back on escape (and │ │131 + // quit when there's nothing left to go back to). │ │132 + if (!try nav.sync(allocator, &ui_session)) terminal.requestQuit(); │ │133 + │ │134 + try nav.root.build(allocator, .{ │ │135 .min_size = .{ .width = null, .height = null }, │ │136 .max_size = .{ .width = last_size.width, .height = last_size.height },│ │133 - }, root.getFocus()); │ │134 - _ = try terminal.render(&root, &last_grid, &last_size); │ │137 + }, nav.root.getFocus()); │ │138 + _ = try terminal.render(&nav.root, &last_grid, &last_size); │ │139 } │ │140 } │ │141 │ ╰───────────────────────────────────────────────────────────────────────────────────────╯