Skip to content

Cancellation on ReadAsync causes next ReadAsync to skip a byte (raw mode) #165

@scottbilas

Description

@scottbilas

I'm unsure if this is a bug or I'm using the API wrong, but a canceled ReadAsync causes the next ReadAsync to ignore the next stdin byte, and then behaves normally after that.

To repro, run the below code. Type 'a', wait to allow the cancel, then type 'b' then 'c'. You will see a "c" for step 3, but it should show a "b".

Is there some state that I need to clear after a ReadAsync cancellation?

using static Vezel.Cathode.Terminal;

EnableRawMode();

var buf = new byte[1];

// read key press, works ok
await OutAsync("1: ");
await ReadAsync(buf);
await OutLineAsync((char)buf[0]);

// do a timeout cancel
try
{
    var cancel = new CancellationTokenSource();
    cancel.CancelAfter(100);

    await OutAsync("2: ");
    await ReadAsync(buf, cancel.Token);
    await OutLineAsync((char)buf[0]);
}
catch (OperationCanceledException)
{
    await OutLineAsync("cancel");
}

// this one requires two keypresses
await OutAsync("3: ");
await ReadAsync(buf);
await OutLineAsync((char)buf[0]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: driversIssues related to the terminal drivers.os: windowsIssues that are specific to Windows (10, 11, etc).state: blockedIssues that are blocked on some other issue or work.

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions