╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ widget.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1361 if (self.choices.len > 1) { 1362 if (root_focus.grandchild_id) |id| { 1363 for (0..self.choices.len) |i| { 1364 if (id != self.selector(i).getFocus().id) continue; 1365 if (i != self.selected) try self.select(allocator, i); 1366 root_focus.setFocus(self.textInput().getFocus().id); 1367 break; 1368 } 1369 } 1370 1371 const focused = root_focus.grandchild_id == self.textInput().getFocus().id; 1372 for (0..self.choices.len) |i| { 1373 self.selector(i).options.border_style = if (i == self.selected) 1374 (if (focused) .double else .single) 1375 else 1376 .hidden; 1377 } 1378 } 1379 self.textInput().options.border_style = .single; 1380 self.textInput().cursor = 0; 1381 self.textInput().scroll_offset = 0; 1382 try self.box.build(allocator, constraint, root_focus); 1383 1384 if (!self.session.is_terminal) { 1385 const aa = self.session.arena.allocator(); 1386 const id = self.textInput().getFocus().id; 1387 try self.session.text_inputs.put(aa, id, self.textInput()); 1388 } 1389 } 1390 1391 pub fn input(self: *CopyableText, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1392 switch (key) { 1393 .arrow_left => if (self.selected > 0) try self.select(allocator, self.selected - 1), 1394 .arrow_right => if (self.selected + 1 < self.choices.len) try self.select(allocator, self.selected + 1), 1395 .enter => if (self.session.is_terminal) self.show(), 1396 .mouse => |mouse| { 1397 if (self.choices.len > 1) for (0..self.choices.len) |i| { 1398 if (!inp.leftClickOn(root_focus, self.selector(i).getFocus().id, mouse)) continue; 1399 try self.select(allocator, i); 1400 root_focus.setFocus(self.textInput().getFocus().id); 1401 return; 1402 }; 1403 if (self.session.is_terminal and !mouse.ctrl and inp.leftClickOn(root_focus, self.textInput().getFocus().id, mouse)) self.show(); 1404 }, 1405 else => {}, 1406 } 1407 } 1408 1409 fn select(self: *CopyableText, allocator: std.mem.Allocator, selected: usize) !void { 1410 self.selected = selected; 1411 const choice = self.choices[selected]; 1412 const text_input = self.textInput(); 1413 text_input.options.label = choice.label; 1414 text_input.options.bottom_label = choice.bottom_label; 1415 try text_input.setContent(allocator, choice.text); 1416 } 1417 1418 fn show(self: *CopyableText) void { 1419 const choice = self.choices[self.selected]; 1420 self.session.host_request = .{ .show_copyable_text = choice.copyable_text orelse choice.text }; 1421 } 1422 1423 fn textInput(self: *CopyableText) *wgt.TextInput { 1424 return &self.box.children.values()[if (self.choices.len > 1) self.choices.len else 0].widget.text_input; 1425 } 1426 1427 fn selector(self: *CopyableText, index: usize) *wgt.TextBox { 1428 return &self.box.children.values()[index].widget.text_box; 1429 } 1430 1431 fn maxWidth(choices: []const Choice) usize { 1432 var width: usize = 0; 1433 for (choices) |choice| width = @max(width, choice.text.len, choice.label.len, choice.bottom_label.len); 1434 return width; 1435 } 1436 1437 pub fn clearGrid(self: *CopyableText) void { 1438 self.box.clearGrid(); 1439 } 1440 1441 pub fn getGrid(self: CopyableText) ?Grid { 1442 return self.box.getGrid(); 1443 } 1444 1445 pub fn getFocus(self: *CopyableText) *Focus { 1446 return self.box.getFocus(); 1447 } 1448 }; 1449