Skip to content

Expose readline.Interface "line", "cursor", "getCursorPos" #30347

Closed
@Js-Brecht

Description

@Js-Brecht

Describe the solution you'd like
I think it would be very useful to be able to access readline.Interface's current line and cursor values, as well as access the _getCursorPos() member function.

It's frequently desirable to draw something outside of the current prompt during input. I am endlessly recreating actions that readline does already; specifically, tracking the cursor position (so listening for left, right, home, end, delete, backspace, ctrl+, etc, etc, ad nauseam), as well as listening to stdin for data, so that I can keep track of what the input looks like. This way, if I want to draw something outside of the prompt, I know where to return the cursor to.

I also see that readline uses Interface._getCursorPos() internally; also very useful, and pretty much what I'm recreating with Interface.line & Interface.cursor calculations.

Being able to read Interface.line at any given time can be important, if you need to use that value somewhere else, but you aren't done with the prompt yet (for example, drawing an autocomplete list)

But it seems awfully redundant to have to do all of this, when readline already does it quite well. Honestly, by the time I'm done, I've basically created my own readline interface. Seems like a waste.

I can read Interface.line, Interface.cursor, etc... but they aren't exposed in @types/node, so it makes me feel like they are omitted for a reason.

Describe alternatives you've considered
There's a couple of alternatives. One, I guess, is to just use the Interface members, and hope they don't ever change. The other is essentially creating my own custom readline interface, which really is just reinventing the wheel.


Perhaps somebody could share the philosophy behind the current design? On the other hand, if they can be safely exposed in the types, I'd be happy to make a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions