Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Bug with readline close() not closing properly in Windows #5927

@danielchatfield

Description

@danielchatfield

I apologise for the awful test case to illustrate the bug:

var readline = require('readline');

var opt = {
    input: process.stdin,
    output: process.stdout
};


var createInterface = function() {
    var rl = readline.createInterface(opt);
    var origWrite = rl._ttyWrite;
    rl._ttyWrite = function( s, key ) {
        key = key || {};
        if ( key.name === "w" ) return;

        origWrite.apply( this, arguments );
    }
    return rl;
};

var rl = createInterface();


var onKeypress = function(s, key) {
    if ( key && (key.name === "enter" || key.name === "return") ) {
        //rl.pause();
        rl.close();
        rl = null;
        rl = createInterface();
    }
}

process.stdin.on( "keypress", onKeypress );

Run this then enter 'qwerty'. (the w will not appear since it is being intercepted by the modified _ttyWrite).

Now hit enter (to close the readline, remove it and create a new one).

Now try typing 'qwerty', it should be the same but it isn't, this time 'qwerty' is printed.

If you uncomment the rl.pause() it works properly - but since rl.pause() is called from within rl.close() I don't have a clue why it doesn't work without it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions