zig icon indicating copy to clipboard operation
zig copied to clipboard

Return type of `std.os.uefi.protocol.simple_text_input.SimpleTextInput.readKeyStroke` should be optional

Open carnivorecookies opened this issue 9 months ago • 0 comments

readKeyStroke should return ReadKeyStrokeError!?Key.Input (from ReadKeyStrokeError!Key.Input), and NotReady should be removed from ReadKeyStrokeError.

readKeyStroke immediately returns, and if no keys were pressed at the time of the call it returns the error ReadKeyStrokeError.NotReady. However, it would make more sense to return null instead because no key was detected. This would allow for less awkward, cleaner code when waiting for input in a UEFI program:

while (true) {
    key = con_in.readKeyStroke() catch |err| switch (err) {
        error.NotReady => continue,
        else => return err,
    };
    // use `key`
}

If the return type of readKeyStroke() were optional, this would be simplified to:

while (try con_in.readKeyStroke()) |key| {
    // use `key`
}

carnivorecookies avatar May 22 '25 01:05 carnivorecookies