Skip to content

in editorReadKey, how to rewrite while statement ? #47

@kurt-steiner

Description

@kurt-steiner

in editorReadKey function, there is a while statement

 while ((nread = read(STDIN_FILENO, &c, 1)) != 1) {
    if (nread == -1 && errno != EAGAIN) die("read");
  }

and when I transform it into

  while(true) {
    nread = read(STDIN_FILENO, &c, 1);
    if(nread != 1) {
      if(nread == -1 && errno != EAGAIN) {
	die("read");
      } else {
	break;
      }
    } else {
      break;
    }
  }

or

  nread = read(STDIN_FILENO, &c, 1);
  if(nread == -1 && errno != EAGAIN) {
    die("read");
  }

but I found that the cursor move too slow when press the arrow key one by one, here is the example using my while statement, comparing the origin while statement

2021-12-06.13-51-47.mp4

what is the wrong with my code ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions