╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Home.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
94 } 95 96 if (session.is_terminal) { 97 var quit_view = try Quit.View.init(allocator, session); 98 errdefer quit_view.deinit(allocator); 99 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 100 } 101 102 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 103 } 104 105 var self = View{ 106 .box = box, 107 .data = data, 108 .session = session, 109 }; 110 self.getFocus().child_id = box.children.keys()[header_index]; 111 return self; 112 } 113 114 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 115 self.box.deinit(allocator); 116 } 117 118 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 119 self.clearGrid(); 120 const header = &self.box.children.values()[header_index].widget.home_header; 121 const stack = &self.box.children.values()[stack_index].widget.stack; 122 123 // each header tab maps 1:1 to a stack child by position; mirror the 124 // selected child's page into the url, keyed by its kind 125 if (header.getSelectedIndex()) |index| { 126 stack.getFocus().child_id = stack.children.keys()[index]; 127 switch (std.meta.activeTag(stack.children.values()[index])) { 128 // mirror each list tab's built pagination window so the url stays 129 // consistent with what's shown (and so a build doesn't reset it). 130 .home_users => self.session.data.current_page = .{ .home_users = self.data.users.start }, 131 .home_repos => self.session.data.current_page = .{ .home_repos = self.data.repos.start }, 132 .home_settings => self.session.data.current_page = .home_settings, 133 .home_auth => self.session.data.current_page = .home_auth, 134 // the quit tab is tty-only and not a route, so leave current_page 135 // alone (nothing to mirror into the url). 136 else => {}, 137 } 138 } 139 try self.box.build(allocator, constraint, root_focus); 140 } 141 142 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 143 if (self.getFocus().child_id) |child_id| { 144 if (self.box.children.getIndex(child_id)) |current_index| { 145 const child = &self.box.children.values()[current_index].widget; 146 var index = current_index; 147 148 const direction = inp.vertDirection(key); 149 150 switch (direction) { 151 .up => { 152 switch (child.*) { 153 .home_header => { 154 try child.input(allocator, key, root_focus); 155 }, 156 .stack => { 157 if (child.stack.getSelected()) |selected_widget| { 158 const at_top = switch (selected_widget.*) { 159 .home_users => |*v| v.getSelectedIndex() == 0, 160 .home_repos => |*v| v.getSelectedIndex() == 0, 161 .home_settings => |*v| v.getSelectedIndex() == 0, 162 .home_auth => |*v| v.getSelectedIndex() == 0, 163 .quit => |*v| v.getSelectedIndex() == 0, 164 else => false, 165 }; 166 if (at_top) { 167 index = header_index; 168 } else { 169 try child.input(allocator, key, root_focus); 170 } 171 } 172 }, 173 else => {}, 174 } 175 }, 176 .down => { 177 switch (child.*) { 178 .home_header => { 179 index = stack_index; 180 }, 181 .stack => { 182 try child.input(allocator, key, root_focus); 183 }, 184 else => {}, 185 } 186 }, 187 .none => { 188 try child.input(allocator, key, root_focus); 189 }, 190 } 191 192 if (index != current_index) { 193 root_focus.setFocus(self.box.children.keys()[index]); 194 } 195 } 196 } 197 } 198 199 pub fn clearGrid(self: *View) void { 200 self.box.clearGrid(); 201 } 202 203 pub fn getGrid(self: View) ?Grid { 204 return self.box.getGrid(); 205 } 206 207 pub fn getFocus(self: *View) *Focus { 208 return self.box.getFocus(); 209 } 210 }; 211