Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Updated promptForInput()

Remove those assignments at the top:

Editor.zig: promptForInput()
    _ = cb;
    _ = saved;

Now our prompt function needs to invoke this PromptCb callback.

Before the loop starts, we want to define some variables:

Editor.zig: promptForInput()
    var k: t.Key = undefined;
    var c: u8 = undefined;
    var cb_args: t.PromptCbArgs = undefined;
    while (true) {

which we'll assign inside the loop:

    while (true) {
        try e.statusMessage("{s}{s}", .{ prompt, al.items });
        try e.refreshScreen();
        const k = try ansi.readKey();
        const c = @intFromEnum(k);
        k = try ansi.readKey();
        c = @intFromEnum(k);
        cb_args = .{ .input = &al, .key = k, .saved = saved };

Before the loop ends, we run the callback, if not null:

        if (cb) |callback| try callback(e, cb_args);
    }
    e.clearStatusMessage();

After the loop, we call it one last time before returning the input:

    e.clearStatusMessage();
    return al;
    e.clearStatusMessage();
    cb_args.final = true;
    if (cb) |callback| try callback(e, cb_args);
    return al;