refactor: zigify imports and correct minor mistakes

This commit is contained in:
2025-05-20 18:23:44 +02:00
parent 50adf32f14
commit aa4adf20f9
26 changed files with 311 additions and 330 deletions

View File

@@ -1,7 +1,4 @@
//! Input module for `zterm`. Contains structs to represent key events and mouse events.
const std = @import("std");
const Point = @import("point.zig").Point;
pub const Mouse = packed struct {
x: u16,
@@ -32,7 +29,7 @@ pub const Mouse = packed struct {
};
pub fn eql(this: @This(), other: @This()) bool {
return std.meta.eql(this, other);
return meta.eql(this, other);
}
pub fn in(this: @This(), origin: Point, size: Point) bool {
@@ -65,7 +62,7 @@ pub const Key = packed struct {
/// }
/// ```
pub fn eql(this: @This(), other: @This()) bool {
return std.meta.eql(this, other);
return meta.eql(this, other);
}
// TODO might be useful to use the std.ascii stuff!
@@ -92,24 +89,25 @@ pub const Key = packed struct {
}
test "isAscii with ascii character" {
try std.testing.expectEqual(true, isAscii(.{ .cp = 'c' }));
try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .ctrl = true } }));
try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true } }));
try std.testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true, .ctrl = true } }));
try testing.expectEqual(true, isAscii(.{ .cp = 'c' }));
try testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .ctrl = true } }));
try testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true } }));
try testing.expectEqual(false, isAscii(.{ .cp = 'c', .mod = .{ .alt = true, .ctrl = true } }));
}
test "isAscii with non-ascii character" {
try std.testing.expectEqual(false, isAscii(.{ .cp = Escape }));
try std.testing.expectEqual(false, isAscii(.{ .cp = Enter }));
try std.testing.expectEqual(false, isAscii(.{ .cp = Enter, .mod = .{ .alt = true } }));
try testing.expectEqual(false, isAscii(.{ .cp = Escape }));
try testing.expectEqual(false, isAscii(.{ .cp = Enter }));
try testing.expectEqual(false, isAscii(.{ .cp = Enter, .mod = .{ .alt = true } }));
}
test "isAscii with excluded input.Delete" {
try std.testing.expectEqual(false, isAscii(.{ .cp = Delete }));
try std.testing.expectEqual(false, isAscii(.{ .cp = Delete, .mod = .{ .alt = false, .ctrl = false } }));
try testing.expectEqual(false, isAscii(.{ .cp = Delete }));
try testing.expectEqual(false, isAscii(.{ .cp = Delete, .mod = .{ .alt = false, .ctrl = false } }));
}
};
// TODO: std.ascii has the escape codes too!
// codepoints for keys
pub const Tab: u21 = 0x09;
pub const Enter: u21 = 0x0D;
@@ -225,3 +223,8 @@ pub const RightHyper: u21 = 57451;
pub const RightMeta: u21 = 57452;
pub const IsoLevel3Shift: u21 = 57453;
pub const IsoLevel5Shift: u21 = 57454;
const std = @import("std");
const meta = std.meta;
const Point = @import("point.zig").Point;
const testing = std.testing;