feat(element/input): make accept event agnostic to u8 and u21 slices
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 50s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 50s
There are now comptime checks in place an the corresponding triggered event will be automatically converted to the correct type to support simple ascii strings (`[]u8`) or utf-8 strings (`[]u21`).
This commit is contained in:
@@ -127,10 +127,7 @@ pub fn main() !void {
|
||||
.key => |key| if (key.eql(.{ .cp = 'c', .mod = .{ .ctrl = true } })) app.quit(),
|
||||
.accept => |input| {
|
||||
defer allocator.free(input);
|
||||
var string = try allocator.alloc(u8, input.len);
|
||||
defer allocator.free(string);
|
||||
for (0.., input) |i, char| string[i] = @intCast(char);
|
||||
log.debug("Accepted input '{s}'", .{string});
|
||||
log.debug("Accepted input '{s}'", .{input});
|
||||
},
|
||||
.err => |err| log.err("Received {s} with message: {s}", .{ @errorName(err.err), err.msg }),
|
||||
else => {},
|
||||
@@ -165,5 +162,5 @@ const zterm = @import("zterm");
|
||||
const Color = zterm.Color;
|
||||
|
||||
const App = zterm.App(union(enum) {
|
||||
accept: []u21,
|
||||
accept: []u8,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user