Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

use readline for prompt() via magic #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wbourne0
Copy link
Contributor

@wbourne0 wbourne0 commented Aug 31, 2022

The old logic for prompt was pretty bad and readline has all of the logic we need + more so I figured we should just use it instead of our own logic.

This does come with a contingency though - this works because stream.Readable, events.EventEmitter, and readline.Interface synchronously handle data pushed to streams. If that were to change (e.g. debouncing event dispatches) then this would fail.


@wbourne0 wbourne0 self-assigned this Aug 31, 2022
Copy link
Contributor

@gburtini gburtini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I see Toby and Alex in the blame for adjacent files, may want to see if either of them have opinions. Did you confirm that this resolves the bug in question (just to be sure we isolated the right cause)?

I can't decide if the test failure is an actual problem or just needs the relevant prompt tests to be updated. It seems like maybe the new prompt style does not support ctrl+c to exit, changing that behavior would be bad to my eye, but I trust your judgement more than mine here. 🤷

@@ -1,34 +1,19 @@
const { readSync, writeSync, openSync } = require("fs");
const { isatty } = require("tty");
const { readSync, writeSync, openSync } = require('fs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, this whole project has inconsistent quoting styles, so we get these painful prettier diffs. I opened #97 and #98 as one-click merge options for how to try to mitigate this if you want.

if (newIndex >= 0 && newIndex <= str.length) {
index = newIndex;
}
while (result == null) rd.readNext();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this eqeq intentional? I don't see any case that the coercion would be desirable.

If it is intentional, maybe leave a comment explaining it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional. It's what's called a "nullish" check. it's somewhat unstandard but handy to know.

a == null returns true if a is nullish (null or undefined).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants