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

std/node: add readline module #5387

Closed
EvanHahn opened this issue May 14, 2020 · 4 comments
Closed

std/node: add readline module #5387

EvanHahn opened this issue May 14, 2020 · 4 comments
Labels

Comments

@EvanHahn
Copy link
Contributor

For completeness, we should add a polyfill for Node's readline module.

@aggmoulik
Copy link

aggmoulik commented May 15, 2020

Hello @EvanHahn @bartlomieju I want to work on this issue. How can I proceed with this?

@EvanHahn
Copy link
Contributor Author

I'll defer to @bartlomieju on this one as I'm not a Deno maintainer.

I recently put up a pull request for util.callbackify in #5415, which may be helpful as inspiration. I copied the tests and source code from the Node source code, and then made modifications as needed.

Again, I'm not a maintainer, but maybe that info will help.

@sant123
Copy link

sant123 commented May 17, 2020

Hi, I wrote this code with Deno.stdin in mind.

const decoder = new TextDecoder();

export async function readLine() {
  let stringInput = '';

  while (true) {
    const buffer = new Uint8Array(1);
    const readStatus = await Deno.stdin.read(buffer);

    // Found EOL
    if (readStatus == null) {
      break;
    }

    const char = decoder.decode(buffer);

    // On Enter, exit
    if (char === '\n') {
      break;
    }

    stringInput += char;
  }

  return stringInput;
}

Credit to @lucacasonato #3614 (comment)

@stale
Copy link

stale bot commented Jan 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 6, 2021
@stale stale bot closed this as completed Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants