╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Settings.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
79 .center = try ui.Center.init(allocator, .{ .stack = stack }), 80 .session = session, 81 .button_id = button_id, 82 }; 83 } 84 85 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 86 self.center.deinit(allocator); 87 } 88 89 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 90 // select the logged-in view when logged in, else the logged-out view. 91 // decided per-frame since the tty doesn't rebuild the page on login. 92 const logged_in = self.session.data.user_id != null; 93 const stack = &self.center.child.stack; 94 if (logged_in) { 95 const box = &stack.children.values()[logged_in_index].box; 96 const button = &box.children.values()[0].widget.text_box; 97 button.box.children.values()[0].widget.text.content = ansiLabel(self.session); 98 } 99 stack.getFocus().child_id = stack.children.keys()[if (logged_in) logged_in_index else logged_out_index]; 100 try self.center.build(allocator, constraint, root_focus); 101 } 102 103 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 104 _ = allocator; 105 if (self.session.data.user_id == null) return; // blank/disabled when logged out 106 switch (key) { 107 .enter => try self.toggle(), 108 .mouse => |mouse| { 109 if (inp.leftClickOn(root_focus, self.button_id, mouse)) { 110 try self.toggle(); 111 } 112 }, 113 else => {}, 114 } 115 } 116 117 fn toggle(self: *View) !void { 118 try self.session.push(.toggle_ansi); 119 } 120 121 pub fn clearGrid(self: *View) void { 122 self.center.clearGrid(); 123 } 124 125 pub fn getGrid(self: View) ?Grid { 126 return self.center.getGrid(); 127 } 128 129 pub fn getFocus(self: *View) *Focus { 130 return self.center.getFocus(); 131 } 132 133 pub fn getSelectedIndex(self: View) ?usize { 134 _ = self; 135 return 0; 136 } 137 }; 138 139 fn ansiLabel(session: *const ui.Session) []const u8 { 140 const label_on = "turn off ANSI art"; 141 const label_off = "turn on ANSI art"; 142 return if (session.data.enable_ansi) label_on else label_off; 143 } 144