╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
219 // auth tab (login / logout). AuthTab defaults to the global ai:/auth 220 // link; repoint its instance at this repo's auth route so it stays local. 221 { 222 var auth_tab = try AuthTab.View.init(allocator, session); 223 errdefer auth_tab.deinit(allocator); 224 auth_tab.text_box.getFocus().kind = .{ .custom = auth_link }; 225 try tab_ids.put(allocator, auth_tab.getFocus().id, {}); 226 if (std.mem.eql(u8, auth_link, current_link)) selected_tab = auth_tab.getFocus().id; 227 try box.children.put(allocator, auth_tab.getFocus().id, .{ 228 .widget = .{ .auth_tab = auth_tab }, 229 .rect = null, 230 .min_size = .{ .width = AuthTab.min_width, .height = null }, 231 }); 232 } 233 234 // quit tab 235 if (session.is_terminal) { 236 var text_box = try wgt.TextBox(ui.Widget).init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 237 errdefer text_box.deinit(allocator); 238 text_box.getFocus().focusable = true; 239 text_box.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 240 try tab_ids.put(allocator, text_box.getFocus().id, {}); 241 try box.children.put(allocator, text_box.getFocus().id, .{ 242 .widget = .{ .text_box = text_box }, 243 .rect = null, 244 // the label is a single column; +2 for the border 245 .min_size = .{ .width = 1 + 2, .height = null }, 246 }); 247 } 248 249 var self = View{ .box = box, .data = data, .tab_ids = tab_ids }; 250 self.getFocus().child_id = selected_tab orelse self.tab_ids.keys()[0]; 251 return self; 252 } 253 254 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 255 self.box.deinit(allocator); 256 self.tab_ids.deinit(allocator); 257 } 258 259 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 260 self.clearGrid(); 261 // only the selected tab shows its border 262 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 263 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 264 .text_box => |*x| x, 265 .auth_tab => |*at| &at.text_box, 266 else => null, 267 }; 268 if (tb) |t| { 269 t.options.border_style = if (self.getFocus().child_id == id) .single else .hidden; 270 } 271 } 272 try self.box.build(allocator, constraint, root_focus); 273 } 274 275 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 276 _ = allocator; 277 const current_tab = self.currentTabIndex() orelse return; 278 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 279 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 280 } 281 } 282 283 pub fn clearGrid(self: *View) void { 284 self.box.clearGrid(); 285 } 286 287 pub fn getGrid(self: View) ?Grid { 288 return self.box.getGrid(); 289 } 290 291 pub fn getFocus(self: *View) *Focus { 292 return self.box.getFocus(); 293 } 294 295 pub fn getSelectedIndex(self: View) ?usize { 296 return self.currentTabIndex(); 297 } 298 299 fn currentTabIndex(self: View) ?usize { 300 const child_id = self.box.focus.child_id orelse return null; 301 return self.tab_ids.getIndex(child_id); 302 } 303 }; 304