Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vaxis: add osc52 copy/paste support #28

Merged
merged 1 commit into from
May 22, 2024

Conversation

neurocyte
Copy link
Contributor

I was not sure where to get an allocator for the pasted text, so I stole the grapheme allocator. Passing an allocator to parse is probably preferrable, but that felt like a large API change so I thought I'd let you decide.

src/Parser.zig Outdated
seq.param_idx += 1;
switch (p) {
52 => {
const allocator = self.grapheme_data.allocator;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to pass an allocator to Tty.run (and Loop.run). The arg name should be like paste_allocator or something? This makes it a bit cleaner and lets people use a different allocator for this than the grapheme_data.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, maybe the vaxis struct should just hold onto the allocator it was passed on init and use that in Tty.run...what do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neurocyte I was probably too late with the second comment before you ran off working on it! Sorry about that. What do you think about storing an allocator in the Vaxis struct to use for this? I think it might be cleaner that way - there are starting to be a lot of allocators passed around, but maybe that's preferred?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. I prefer to passing allocators explicitly to functions if at all possible. But I'm not using Loop.run or Tty.run so it's really up to you.

src/Vaxis.zig Outdated Show resolved Hide resolved
@rockorager
Copy link
Owner

Thanks for the PR! There is another spot in Tty.run that needs to handle the new event, also:

libvaxis/src/Tty.zig

Lines 157 to 225 in 1dc90bd

const event = result.event orelse continue;
switch (event) {
.key_press => |key| {
if (@hasField(Event, "key_press")) {
// HACK: yuck. there has to be a better way
var mut_key = key;
if (key.text) |text| {
mut_key.text = cache.put(text);
}
loop.postEvent(.{ .key_press = mut_key });
}
},
.key_release => |*key| {
if (@hasField(Event, "key_release")) {
// HACK: yuck. there has to be a better way
var mut_key = key;
if (key.text) |text| {
mut_key.text = cache.put(text);
}
loop.postEvent(.{ .key_release = mut_key });
}
},
.mouse => |mouse| {
if (@hasField(Event, "mouse")) {
loop.postEvent(.{ .mouse = mouse });
}
},
.focus_in => {
if (@hasField(Event, "focus_in")) {
loop.postEvent(.focus_in);
}
},
.focus_out => {
if (@hasField(Event, "focus_out")) {
loop.postEvent(.focus_out);
}
},
.paste_start => {
if (@hasField(Event, "paste_start")) {
loop.postEvent(.paste_start);
}
},
.paste_end => {
if (@hasField(Event, "paste_end")) {
loop.postEvent(.paste_end);
}
},
.cap_kitty_keyboard => {
log.info("kitty keyboard capability detected", .{});
loop.vaxis.caps.kitty_keyboard = true;
},
.cap_kitty_graphics => {
if (!loop.vaxis.caps.kitty_graphics) {
log.info("kitty graphics capability detected", .{});
loop.vaxis.caps.kitty_graphics = true;
}
},
.cap_rgb => {
log.info("rgb capability detected", .{});
loop.vaxis.caps.rgb = true;
},
.cap_unicode => {
log.info("unicode capability detected", .{});
loop.vaxis.caps.unicode = .unicode;
loop.vaxis.screen.width_method = .unicode;
},
.cap_da1 => {
std.Thread.Futex.wake(&loop.vaxis.query_futex, 10);
},

@rockorager rockorager merged commit d48826c into rockorager:main May 22, 2024
@rockorager
Copy link
Owner

Thanks! I made a couple changes. The allocator for pastes is now passed as an option to the vaxis init function. This let's people opt out in a nice way if they don't need that functionality.

@neurocyte neurocyte deleted the copy_paste branch May 22, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants