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