diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig b/vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig new file mode 100644 index 00000000..fbe53912 --- /dev/null +++ b/vendor/libghostty-vt/src/config/ClipboardCodepointMap.zig @@ -0,0 +1,44 @@ +/// ClipboardCodepointMap is a map of codepoints to replacement values +/// for clipboard operations. When copying text to clipboard, matching +/// codepoints will be replaced with their mapped values. +const ClipboardCodepointMap = @This(); + +const std = @import("std"); +const assert = @import("../quirks.zig").inlineAssert; +const Allocator = std.mem.Allocator; + +// To ease our usage later, we map it directly to formatter entries. +pub const Entry = @import("../terminal/formatter.zig").CodepointMap; +pub const Replacement = Entry.Replacement; + +/// The list of entries. We use a multiarraylist for cache-friendly lookups. +/// +/// Note: we do a linear search because we expect to always have very +/// few entries, so the overhead of a binary search is not worth it. +list: std.MultiArrayList(Entry) = .{}, + +pub fn deinit(self: *ClipboardCodepointMap, alloc: Allocator) void { + self.list.deinit(alloc); +} + +/// Deep copy of the struct. The given allocator is expected to +/// be an arena allocator of some sort since the struct itself +/// doesn't support fine-grained deallocation of fields. +pub fn clone(self: *const ClipboardCodepointMap, alloc: Allocator) !ClipboardCodepointMap { + var list = try self.list.clone(alloc); + for (list.items(.replacement)) |*r| switch (r.*) { + .string => |s| r.string = try alloc.dupe(u8, s), + .codepoint => {}, // no allocation needed + }; + + return .{ .list = list }; +} + +/// Add an entry to the map. +/// +/// For conflicting codepoints, entries added later take priority over +/// entries added earlier. +pub fn add(self: *ClipboardCodepointMap, alloc: Allocator, entry: Entry) !void { + assert(entry.range[0] <= entry.range[1]); + try self.list.append(alloc, entry); +} |
