╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1621 1622 if (!self.session.is_terminal) { 1623 const aa = self.session.arena.allocator(); 1624 const id = self.textInput().getFocus().id; 1625 try self.session.text_inputs.put(aa, id, self.textInput()); 1626 } 1627 } 1628 1629 pub fn input(self: *CopyableText, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1630 switch (key) { 1631 .arrow_left => if (self.selected > 0) try self.select(allocator, self.selected - 1), 1632 .arrow_right => if (self.selected + 1 < self.choices.len) try self.select(allocator, self.selected + 1), 1633 .enter => if (self.session.is_terminal) self.show(), 1634 .mouse => |mouse| { 1635 if (self.choices.len > 1) for (0..self.choices.len) |i| { 1636 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 1637 try self.select(allocator, i); 1638 root_focus.setFocus(self.textInput().getFocus().id); 1639 return; 1640 }; 1641 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 1642 }, 1643 else => {}, 1644 } 1645 } 1646 1647 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 1648 self.selected = selected; 1649 const choice = self.choices[selected]; 1650 const text_input = self.textInput(); 1651 text_input.options.label = choice.label; 1652 text_input.options.bottom_label = choice.bottom_label; 1653 try text_input.setContent(allocator, choice.text); 1654 } 1655 1656 fn show(self: *CopyableText) void { 1657 const choice = self.choices[self.selected]; 1658 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 1659 } 1660 1661 fn textInput(self: *CopyableText) *wgt.TextInput { 1662 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 1663 } 1664 1665 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 1666 return &self.box.children.values()[index].widget.text_box; 1667 } 1668 1669 fn maxWidth(choices: []const Choice) usize { 1670 var width: usize = 0; 1671 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 1672 return width; 1673 } 1674 1675 pub fn clearGrid(self: *CopyableText) void { 1676 self.box.clearGrid(); 1677 } 1678 1679 pub fn getGrid(self: CopyableText) ?Grid { 1680 return self.box.getGrid(); 1681 } 1682 1683 pub fn getFocus(self: *CopyableText) *Focus { 1684 return self.box.getFocus(); 1685 } 1686 }; 1687