╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1966 .mouse => |mouse| { 1967 if (self.choices.len > 1) for (0..self.choices.len) |i| { 1968 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 1969 try self.select(allocator, i); 1970 root_focus.setFocus(self.textInput().getFocus().id); 1971 return; 1972 }; 1973 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 1974 }, 1975 else => {}, 1976 } 1977 } 1978 1979 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 1980 self.selected = selected; 1981 const choice = self.choices[selected]; 1982 const text_input = self.textInput(); 1983 text_input.options.label = choice.label; 1984 text_input.options.bottom_label = choice.bottom_label; 1985 try text_input.setContent(allocator, choice.text); 1986 } 1987 1988 fn show(self: *CopyableText) void { 1989 const choice = self.choices[self.selected]; 1990 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 1991 } 1992 1993 fn textInput(self: *CopyableText) *wgt.TextInput { 1994 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 1995 } 1996 1997 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 1998 return &self.box.children.values()[index].widget.text_box; 1999 } 2000 2001 fn maxWidth(choices: []const Choice) usize { 2002 var width: usize = 0; 2003 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 2004 return width; 2005 } 2006 2007 pub fn clearGrid(self: *CopyableText) void { 2008 self.box.clearGrid(); 2009 } 2010 2011 pub fn getGrid(self: CopyableText) ?Grid { 2012 return self.box.getGrid(); 2013 } 2014 2015 pub fn getFocus(self: *CopyableText) *Focus { 2016 return self.box.getFocus(); 2017 } 2018 }; 2019