Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in editorReadKey, how to rewrite while statement ? #47

Open
nesteiner opened this issue Dec 6, 2021 · 0 comments
Open

in editorReadKey, how to rewrite while statement ? #47

nesteiner opened this issue Dec 6, 2021 · 0 comments

Comments

@nesteiner
Copy link

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 ??

@nesteiner nesteiner changed the title in editorReadKey, how to modify while in editorReadKey, how to rewrite while statement ? Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant