╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2021 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 2022 try self.select(allocator, i); 2023 root_focus.setFocus(self.textInput().getFocus().id); 2024 return; 2025 }; 2026 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 2027 }, 2028 else => {}, 2029 } 2030 } 2031 2032 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 2033 self.selected = selected; 2034 const choice = self.choices[selected]; 2035 const text_input = self.textInput(); 2036 text_input.options.label = choice.label; 2037 text_input.options.bottom_label = choice.bottom_label; 2038 try text_input.setContent(allocator, choice.text); 2039 } 2040 2041 fn show(self: *CopyableText) void { 2042 const choice = self.choices[self.selected]; 2043 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 2044 } 2045 2046 fn textInput(self: *CopyableText) *wgt.TextInput { 2047 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 2048 } 2049 2050 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 2051 return &self.box.children.values()[index].widget.text_box; 2052 } 2053 2054 fn maxWidth(choices: []const Choice) usize { 2055 var width: usize = 0; 2056 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 2057 return width; 2058 } 2059 2060 pub fn clearGrid(self: *CopyableText) void { 2061 self.box.clearGrid(); 2062 } 2063 2064 pub fn getGrid(self: CopyableText) ?Grid { 2065 return self.box.getGrid(); 2066 } 2067 2068 pub fn getFocus(self: *CopyableText) *Focus { 2069 return self.box.getFocus(); 2070 } 2071 }; 2072