╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1602 1603 pub fn input(self: *CopyableText, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1604 switch (key) { 1605 .arrow_left => if (self.selected > 0) try self.select(allocator, self.selected - 1), 1606 .arrow_right => if (self.selected + 1 < self.choices.len) try self.select(allocator, self.selected + 1), 1607 .enter => if (self.session.is_terminal) self.show(), 1608 .mouse => |mouse| { 1609 if (self.choices.len > 1) for (0..self.choices.len) |i| { 1610 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 1611 try self.select(allocator, i); 1612 root_focus.setFocus(self.textInput().getFocus().id); 1613 return; 1614 }; 1615 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 1616 }, 1617 else => {}, 1618 } 1619 } 1620 1621 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 1622 self.selected = selected; 1623 const choice = self.choices[selected]; 1624 const text_input = self.textInput(); 1625 text_input.options.label = choice.label; 1626 text_input.options.bottom_label = choice.bottom_label; 1627 try text_input.setContent(allocator, choice.text); 1628 } 1629 1630 fn show(self: *CopyableText) void { 1631 const choice = self.choices[self.selected]; 1632 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 1633 } 1634 1635 fn textInput(self: *CopyableText) *wgt.TextInput { 1636 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 1637 } 1638 1639 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 1640 return &self.box.children.values()[index].widget.text_box; 1641 } 1642 1643 fn maxWidth(choices: []const Choice) usize { 1644 var width: usize = 0; 1645 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 1646 return width; 1647 } 1648 1649 pub fn clearGrid(self: *CopyableText) void { 1650 self.box.clearGrid(); 1651 } 1652 1653 pub fn getGrid(self: CopyableText) ?Grid { 1654 return self.box.getGrid(); 1655 } 1656 1657 pub fn getFocus(self: *CopyableText) *Focus { 1658 return self.box.getFocus(); 1659 } 1660 }; 1661