~leon_plickat/nfm

d0cac293d73d4eb4e2a638321b9e2137fe3907cc — Leon Henrik Plickat 3 months ago 38e0bb2
Do the bit converting of alphabetical char to control char at comptime
1 files changed, 6 insertions(+), 4 deletions(-)

M src/UserInterface.zig
M src/UserInterface.zig => src/UserInterface.zig +6 -4
@@ 406,10 406,12 @@ pub fn nextEvent(self: *Self) !?Event {
    }

    // Legacy codes for Ctrl-[a-z]. This is missing 'm', as that would match Enter.
    const chars = [_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w' };
    for (chars) |char| {
        if (buffer[0] == char & '\x1f') return Event{ .ctrl = char };
    }
    const chars = comptime blk: {
        var chars = [_]u8{ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w' };
        for (chars) |*ch| ch.* &= '\x1f';
        break :blk chars;
    };
    for (chars) |char| if (buffer[0] == char) return Event{ .ctrl = char };

    return Event{ .ascii = buffer[0] };
}