╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main_wasm.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
10 fn updateHtml() !void { 11 const root_ptr = if (root) |*root_value| root_value else return error.NotStarted; 12 const html = try ui.generateHtml(allocator, root_ptr); 13 defer allocator.free(html); 14 setHtml(html); 15 } 16 17 fn start() !void { 18 var next_root = try ui.initRoot(allocator); 19 errdefer next_root.deinit(); 20 21 if (root) |*old_root| old_root.deinit(); 22 root = next_root; 23 24 try updateHtml(); 25 } 26 27 fn tick() !void { 28 const root_ptr = if (root) |*root_value| root_value else return error.NotStarted; 29 try ui.buildRoot(root_ptr, 80, 24); 30 try updateHtml(); 31 } 32 33 fn onKeyDown(key_code: u32) !void { 34 const root_ptr = if (root) |*root_value| root_value else return error.NotStarted; 35 const key: inp.Key = switch (key_code) { 36 33 => .page_up, 37 34 => .page_down, 38 35 => .end, 39 36 => .home, 40 38 => .arrow_up, 41 40 => .arrow_down, 42 else => return, 43 }; 44 try root_ptr.input(key, root_ptr.getFocus()); 45 } 46 47 fn consoleLog(arg: []const u8) void { 48 _consoleLog(arg.ptr, @intCast(arg.len)); 49 } 50 51 fn setHtml(arg: []const u8) void { 52 _setHtml(arg.ptr, @intCast(arg.len)); 53 } 54 55 extern fn _consoleLog(arg: [*]const u8, len: u32) void; 56 extern fn _setHtml(arg: [*]const u8, len: u32) void; 57 58 export fn _start() void { 59 start() catch |err| { 60 var buf: [256]u8 = undefined; 61 const str = std.fmt.bufPrint(&buf, "start: {}", .{err}) catch unreachable; 62 consoleLog(str); 63 }; 64 } 65 66 export fn _tick() bool { 67 tick() catch |err| { 68 var buf: [256]u8 = undefined; 69 const str = std.fmt.bufPrint(&buf, "tick: {}", .{err}) catch unreachable; 70 consoleLog(str); 71 return false; 72 }; 73 return true; 74 } 75 76 export fn _onKeyDown(key_code: u32) void { 77 onKeyDown(key_code) catch |err| { 78 var buf: [256]u8 = undefined; 79 const str = std.fmt.bufPrint(&buf, "onKeyDown: {}", .{err}) catch unreachable; 80 consoleLog(str); 81 }; 82 } 83