╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
248 { 249 var auth_view = try Auth.View.init(allocator, &data.auth, session); 250 errdefer auth_view.deinit(allocator); 251 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 252 } 253 254 if (session.is_terminal) { 255 var quit_view = try Quit.View.init(allocator, session); 256 errdefer quit_view.deinit(allocator); 257 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 258 } 259 260 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 261 } 262 263 var self = View{ .box = box }; 264 self.getFocus().child_id = box.children.keys()[header_index]; 265 return self; 266 } 267 268 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 269 self.box.deinit(allocator); 270 } 271 272 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 273 self.clearGrid(); 274 const header = &self.box.children.values()[header_index].widget.user_header; 275 const stack = &self.box.children.values()[stack_index].widget.stack; 276 277 // each header tab maps 1:1 to a stack child by position 278 if (header.getSelectedIndex()) |index| 279 stack.getFocus().child_id = stack.children.keys()[index]; 280 try self.box.build(allocator, constraint, root_focus); 281 } 282 283 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 284 if (self.getFocus().child_id) |child_id| { 285 if (self.box.children.getIndex(child_id)) |current_index| { 286 const child = &self.box.children.values()[current_index].widget; 287 var index = current_index; 288 289 const direction = inp.vertDirection(key); 290 291 switch (direction) { 292 .up => { 293 switch (child.*) { 294 .user_header => { 295 try child.input(allocator, key, root_focus); 296 }, 297 .stack => { 298 if (child.stack.getSelected()) |selected_widget| { 299 if (selected_widget.atTop(root_focus)) { 300 index = header_index; 301 } else { 302 try child.input(allocator, key, root_focus); 303 } 304 } 305 }, 306 else => {}, 307 } 308 }, 309 .down => { 310 switch (child.*) { 311 .user_header => { 312 index = stack_index; 313 }, 314 .stack => { 315 try child.input(allocator, key, root_focus); 316 }, 317 else => {}, 318 } 319 }, 320 .none => { 321 try child.input(allocator, key, root_focus); 322 }, 323 } 324 325 if (index != current_index) { 326 root_focus.setFocus(self.box.children.keys()[index]); 327 } 328 } 329 } 330 } 331 332 pub fn clearGrid(self: *View) void { 333 self.box.clearGrid(); 334 } 335 336 pub fn getGrid(self: View) ?Grid { 337 return self.box.getGrid(); 338 } 339 340 pub fn getFocus(self: *View) *Focus { 341 return self.box.getFocus(); 342 } 343 }; 344