╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2113 if (self.choices.len > 1) for (0..self.choices.len) |i| { 2114 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 2115 try self.select(allocator, i); 2116 root_focus.setFocus(self.textInput().getFocus().id); 2117 return; 2118 }; 2119 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 2120 }, 2121 else => {}, 2122 } 2123 } 2124 2125 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 2126 self.selected = selected; 2127 const choice = self.choices[selected]; 2128 const text_input = self.textInput(); 2129 text_input.options.top_label.text = choice.label; 2130 text_input.options.bottom_label.text = choice.bottom_label; 2131 try text_input.setContent(allocator, choice.text); 2132 } 2133 2134 fn show(self: *CopyableText) void { 2135 const choice = self.choices[self.selected]; 2136 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 2137 } 2138 2139 fn textInput(self: *CopyableText) *wgt.TextInput { 2140 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 2141 } 2142 2143 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 2144 return &self.box.children.values()[index].widget.text_box; 2145 } 2146 2147 fn maxWidth(choices: []const Choice) usize { 2148 var width: usize = 0; 2149 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 2150 return width; 2151 } 2152 2153 pub fn clearGrid(self: *CopyableText) void { 2154 self.box.clearGrid(); 2155 } 2156 2157 pub fn getGrid(self: CopyableText) ?Grid { 2158 return self.box.getGrid(); 2159 } 2160 2161 pub fn getFocus(self: *CopyableText) *Focus { 2162 return self.box.getFocus(); 2163 } 2164 }; 2165