╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
200 try items.append(aa, .{ 201 .text = try std.fmt.allocPrint(aa, "{s} - {s}", .{ repo.event.name, repo.event.description }), 202 .link = try std.fmt.allocPrint(aa, "a:/repo/{s}/{s}", .{ data.user.name, repo.event.name }), 203 }); 204 if (data.repos_next_start) |next_start| 205 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/repos/start:{d}", .{ data.user.name, next_start }) }); 206 try list.setItems(allocator, items.items); 207 208 try stack.children.put(allocator, list.getFocus().id, .{ .flow_box_scroll = list }); 209 } 210 211 // forks list 212 { 213 var list = try ui.widget.FlowBox.Scroll.init(allocator, .{}, !session.is_terminal); 214 errdefer list.deinit(allocator); 215 216 var item_arena = std.heap.ArenaAllocator.init(allocator); 217 defer item_arena.deinit(); 218 const aa = item_arena.allocator(); 219 var items: std.ArrayList(ui.widget.FlowBox.Item) = .empty; 220 if (data.forks_start > 0) 221 try items.append(aa, .{ .text = "← previous", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, data.forks_start -| page_size }) }); 222 for (data.forks) |fork_item| 223 try items.append(aa, .{ .text = try std.fmt.allocPrint(aa, "{s}\n{s}", .{ fork_item.target, fork_item.title }), .link = "" }); 224 if (data.forks_next_start) |next_start| 225 try items.append(aa, .{ .text = "next →", .link = try std.fmt.allocPrint(aa, "a:/user/{s}/forks/start:{d}", .{ data.user.name, next_start }) }); 226 try list.setItems(allocator, items.items); 227 try stack.children.put(allocator, list.getFocus().id, .{ .flow_box_scroll = list }); 228 } 229 230 // the header has no settings tab without a login, so keep the 231 // stack's children 1:1 with the tabs by skipping the view too 232 if (session.data.user_id != null) { 233 var settings_view = try Settings.View.init(allocator, session); 234 errdefer settings_view.deinit(allocator); 235 try stack.children.put(allocator, settings_view.getFocus().id, .{ .home_settings = settings_view }); 236 } 237 238 { 239 var auth_view = try Auth.View.init(allocator, &data.auth, session); 240 errdefer auth_view.deinit(allocator); 241 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 242 } 243 244 if (session.is_terminal) { 245 var quit_view = try Quit.View.init(allocator, session); 246 errdefer quit_view.deinit(allocator); 247 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 248 } 249 250 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 251 } 252 253 var self = View{ .box = box }; 254 self.getFocus().child_id = box.children.keys()[header_index]; 255 return self; 256 } 257 258 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 259 self.box.deinit(allocator); 260 } 261 262 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 263 self.clearGrid(); 264 const header = &self.box.children.values()[header_index].widget.user_header; 265 const stack = &self.box.children.values()[stack_index].widget.stack; 266 267 // each header tab maps 1:1 to a stack child by position 268 if (header.getSelectedIndex()) |index| 269 stack.getFocus().child_id = stack.children.keys()[index]; 270 try self.box.build(allocator, constraint, root_focus); 271 } 272 273 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 274 if (self.getFocus().child_id) |child_id| { 275 if (self.box.children.getIndex(child_id)) |current_index| { 276 const child = &self.box.children.values()[current_index].widget; 277 var index = current_index; 278 279 const direction = inp.vertDirection(key); 280 281 switch (direction) { 282 .up => { 283 switch (child.*) { 284 .user_header => { 285 try child.input(allocator, key, root_focus); 286 }, 287 .stack => { 288 if (child.stack.getSelected()) |selected_widget| { 289 const at_top = switch (selected_widget.*) { 290 .flow_box_scroll => |*v| v.getSelectedIndex() == 0, 291 .home_settings => |*v| v.getSelectedIndex() == 0, 292 .home_auth => |*v| v.getSelectedIndex() == 0, 293 .quit => |*v| v.getSelectedIndex() == 0, 294 else => false, 295 }; 296 if (at_top) { 297 index = header_index; 298 } else { 299 try child.input(allocator, key, root_focus); 300 } 301 } 302 }, 303 else => {}, 304 } 305 }, 306 .down => { 307 switch (child.*) { 308 .user_header => { 309 index = stack_index; 310 }, 311 .stack => { 312 try child.input(allocator, key, root_focus); 313 }, 314 else => {}, 315 } 316 }, 317 .none => { 318 try child.input(allocator, key, root_focus); 319 }, 320 } 321 322 if (index != current_index) { 323 root_focus.setFocus(self.box.children.keys()[index]); 324 } 325 } 326 } 327 } 328 329 pub fn clearGrid(self: *View) void { 330 self.box.clearGrid(); 331 } 332 333 pub fn getGrid(self: View) ?Grid { 334 return self.box.getGrid(); 335 } 336 337 pub fn getFocus(self: *View) *Focus { 338 return self.box.getFocus(); 339 } 340 }; 341