╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main_wasm.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
185 const slice = allocator.alloc(u8, len) catch return null; 186 return slice.ptr; 187 } 188 189 export fn _init(json_ptr: [*]u8, json_len: u32, min_height: u32, max_width: u32) void { 190 const json = json_ptr[0..json_len]; 191 defer allocator.free(json); 192 init(json, min_height, max_width) catch |err| { 193 var buf: [256]u8 = undefined; 194 const str = std.fmt.bufPrint(&buf, "init: {}", .{err}) catch unreachable; 195 consoleLog(str); 196 }; 197 } 198 199 export fn _tick(min_height: u32, max_width: u32) bool { 200 tick(min_height, max_width) catch |err| { 201 var buf: [256]u8 = undefined; 202 const str = std.fmt.bufPrint(&buf, "tick: {}", .{err}) catch unreachable; 203 consoleLog(str); 204 return false; 205 }; 206 return true; 207 } 208 209 export fn _onKeyDown(key_code: u32) void { 210 onKeyDown(key_code) catch |err| { 211 var buf: [256]u8 = undefined; 212 const str = std.fmt.bufPrint(&buf, "onKeyDown: {}", .{err}) catch unreachable; 213 consoleLog(str); 214 }; 215 } 216 217 export fn _onMouseClick(focus_id: u32) void { 218 onMouseClick(focus_id) catch |err| { 219 var buf: [256]u8 = undefined; 220 const str = std.fmt.bufPrint(&buf, "onMouseClick: {}", .{err}) catch unreachable; 221 consoleLog(str); 222 }; 223 } 224 225 export fn _setFocus(focus_id: u32) void { 226 setFocus(focus_id) catch |err| { 227 var buf: [256]u8 = undefined; 228 const str = std.fmt.bufPrint(&buf, "setFocus: {}", .{err}) catch unreachable; 229 consoleLog(str); 230 }; 231 } 232 233 // js calls this when the value of an overlay <input> changes; we replace 234 // the matching TextInput's content with the supplied utf-8 bytes. 235 export fn _setTextInputValue(focus_id: u32, value_ptr: [*]const u8, value_len: u32) void { 236 setTextInputValue(focus_id, value_ptr[0..value_len]) catch |err| { 237 var buf: [256]u8 = undefined; 238 const str = std.fmt.bufPrint(&buf, "setTextInputValue: {}", .{err}) catch unreachable; 239 consoleLog(str); 240 }; 241 } 242 243 fn setTextInputValue(focus_id: u32, bytes: []const u8) !void { 244 const root_ptr = if (root) |*r| r else return error.NotStarted; 245 const root_focus = root_ptr.getFocus(); 246 const child = root_focus.children.get(focus_id) orelse return error.UnknownFocusId; 247 switch (child.focus.kind) { 248 .text_input, .text_input_password => {}, 249 else => return error.NotATextInput, 250 } 251 const ti: *wgt.TextInput(ui.Widget) = @fieldParentPtr("focus", child.focus); 252 try ti.setContent(allocator, bytes); 253 // mirror the TTY behavior in Login.View.input: editing an input clears 254 // the stale failure flag so the "(invalid)" label doesn't linger after 255 // the user has typed a correction 256 session.data.login_failure = null; 257 } 258