╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1995 if (root_focus.grandchild_id) |id| { 1996 for (0..self.choices.len) |i| { 1997 if (id != self.selector(i).getFocus().id) continue; 1998 if (i != self.selected) try self.select(allocator, i); 1999 root_focus.setFocus(self.textInput().getFocus().id); 2000 break; 2001 } 2002 } 2003 2004 const focused = root_focus.grandchild_id == self.textInput().getFocus().id; 2005 for (0..self.choices.len) |i| { 2006 self.selector(i).options.border = if (i == self.selected) 2007 (if (focused) .double else .single) 2008 else 2009 .hidden; 2010 } 2011 } 2012 self.textInput().options.border = .single; 2013 self.textInput().cursor = 0; 2014 self.textInput().scroll_offset = 0; 2015 try self.box.build(allocator, constraint, root_focus); 2016 2017 if (!self.session.is_terminal) { 2018 const aa = self.session.arena.allocator(); 2019 const id = self.textInput().getFocus().id; 2020 try self.session.text_inputs.put(aa, id, self.textInput()); 2021 } 2022 } 2023 2024 pub fn input(self: *CopyableText, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2025 switch (key) { 2026 .arrow_left => if (self.selected > 0) try self.select(allocator, self.selected - 1), 2027 .arrow_right => if (self.selected + 1 < self.choices.len) try self.select(allocator, self.selected + 1), 2028 .enter => if (self.session.is_terminal) self.show(), 2029 .mouse => |mouse| { 2030 if (self.choices.len > 1) for (0..self.choices.len) |i| { 2031 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 2032 try self.select(allocator, i); 2033 root_focus.setFocus(self.textInput().getFocus().id); 2034 return; 2035 }; 2036 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 2037 }, 2038 else => {}, 2039 } 2040 } 2041 2042 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 2043 self.selected = selected; 2044 const choice = self.choices[selected]; 2045 const text_input = self.textInput(); 2046 text_input.options.top_label.text = choice.label; 2047 text_input.options.bottom_label.text = choice.bottom_label; 2048 try text_input.setContent(allocator, choice.text); 2049 } 2050 2051 fn show(self: *CopyableText) void { 2052 const choice = self.choices[self.selected]; 2053 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 2054 } 2055 2056 fn textInput(self: *CopyableText) *wgt.TextInput { 2057 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 2058 } 2059 2060 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 2061 return &self.box.children.values()[index].widget.text_box; 2062 } 2063 2064 fn maxWidth(choices: []const Choice) usize { 2065 var width: usize = 0; 2066 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 2067 return width; 2068 } 2069 2070 pub fn clearGrid(self: *CopyableText) void { 2071 self.box.clearGrid(); 2072 } 2073 2074 pub fn getGrid(self: CopyableText) ?Grid { 2075 return self.box.getGrid(); 2076 } 2077 2078 pub fn getFocus(self: *CopyableText) *Focus { 2079 return self.box.getFocus(); 2080 } 2081 }; 2082