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