╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2052 for (0..self.choices.len) |i| { 2053 self.selector(i).options.border = if (i == self.selected) 2054 (if (focused) .double else .single) 2055 else 2056 .hidden; 2057 } 2058 } 2059 self.textInput().options.border = .single; 2060 self.textInput().cursor = 0; 2061 self.textInput().scroll_offset = 0; 2062 try self.box.build(allocator, constraint, root_focus); 2063 2064 if (!self.session.is_terminal) { 2065 const aa = self.session.arena.allocator(); 2066 const id = self.textInput().getFocus().id; 2067 try self.session.text_inputs.put(aa, id, self.textInput()); 2068 } 2069 } 2070 2071 pub fn input(self: *CopyableText, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2072 switch (key) { 2073 .arrow_left => if (self.selected > 0) try self.select(allocator, self.selected - 1), 2074 .arrow_right => if (self.selected + 1 < self.choices.len) try self.select(allocator, self.selected + 1), 2075 .enter => if (self.session.is_terminal) self.show(), 2076 .mouse => |mouse| { 2077 if (self.choices.len > 1) for (0..self.choices.len) |i| { 2078 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 2079 try self.select(allocator, i); 2080 root_focus.setFocus(self.textInput().getFocus().id); 2081 return; 2082 }; 2083 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 2084 }, 2085 else => {}, 2086 } 2087 } 2088 2089 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 2090 self.selected = selected; 2091 const choice = self.choices[selected]; 2092 const text_input = self.textInput(); 2093 text_input.options.top_label.text = choice.label; 2094 text_input.options.bottom_label.text = choice.bottom_label; 2095 try text_input.setContent(allocator, choice.text); 2096 } 2097 2098 fn show(self: *CopyableText) void { 2099 const choice = self.choices[self.selected]; 2100 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 2101 } 2102 2103 fn textInput(self: *CopyableText) *wgt.TextInput { 2104 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 2105 } 2106 2107 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 2108 return &self.box.children.values()[index].widget.text_box; 2109 } 2110 2111 fn maxWidth(choices: []const Choice) usize { 2112 var width: usize = 0; 2113 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 2114 return width; 2115 } 2116 2117 pub fn clearGrid(self: *CopyableText) void { 2118 self.box.clearGrid(); 2119 } 2120 2121 pub fn getGrid(self: CopyableText) ?Grid { 2122 return self.box.getGrid(); 2123 } 2124 2125 pub fn getFocus(self: *CopyableText) *Focus { 2126 return self.box.getFocus(); 2127 } 2128 }; 2129