╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Home.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
128 // consistent with what's shown (and so a build doesn't reset it). 129 .home_users => self.session.data.current_page = .{ .home_users = self.data.users.after }, 130 .home_repos => self.session.data.current_page = .{ .home_repos = self.data.repos.after }, 131 .home_settings => self.session.data.current_page = .home_settings, 132 .home_auth => self.session.data.current_page = .home_auth, 133 // the quit tab is tty-only and not a route, so leave current_page 134 // alone (nothing to mirror into the url). 135 else => {}, 136 } 137 } 138 try self.box.build(allocator, constraint, root_focus); 139 } 140 141 pub fn input(self: *View, allocator: std.mem.Allocator, key: inp.Key, root_focus: *Focus) !void { 142 if (self.getFocus().child_id) |child_id| { 143 if (self.box.children.getIndex(child_id)) |current_index| { 144 const child = &self.box.children.values()[current_index].widget; 145 var index = current_index; 146 147 const Direction = enum { up, down, none }; 148 const direction: Direction = switch (key) { 149 .arrow_up => .up, 150 .arrow_down => .down, 151 .mouse => |mouse| if (mouse.action == .scroll) 152 (if (mouse.action.scroll == .up) .up else .down) 153 else 154 .none, 155 else => .none, 156 }; 157 158 switch (direction) { 159 .up => { 160 switch (child.*) { 161 .home_header => { 162 try child.input(allocator, key, root_focus); 163 }, 164 .stack => { 165 if (child.stack.getSelected()) |selected_widget| { 166 const at_top = switch (selected_widget.*) { 167 .home_users => |*v| v.getSelectedIndex() == 0, 168 .home_repos => |*v| v.getSelectedIndex() == 0, 169 .home_settings => |*v| v.getSelectedIndex() == 0, 170 .home_auth => |*v| v.getSelectedIndex() == 0, 171 .quit => |*v| v.getSelectedIndex() == 0, 172 else => false, 173 }; 174 if (at_top) { 175 index = header_index; 176 } else { 177 try child.input(allocator, key, root_focus); 178 } 179 } 180 }, 181 else => {}, 182 } 183 }, 184 .down => { 185 switch (child.*) { 186 .home_header => { 187 index = stack_index; 188 }, 189 .stack => { 190 try child.input(allocator, key, root_focus); 191 }, 192 else => {}, 193 } 194 }, 195 .none => { 196 try child.input(allocator, key, root_focus); 197 }, 198 } 199 200 if (index != current_index) { 201 root_focus.setFocus(self.box.children.keys()[index]); 202 } 203 } 204 } 205 } 206 207 pub fn clearGrid(self: *View) void { 208 self.box.clearGrid(); 209 } 210 211 pub fn getGrid(self: View) ?Grid { 212 return self.box.getGrid(); 213 } 214 215 pub fn getFocus(self: *View) *Focus { 216 return self.box.getFocus(); 217 } 218 }; 219