Skip to content

Unable to exit REPL via escape codes when TERM=dumb #29111

Description

@silverwind

^C or ^D do not exit the REPL when TERM=dumb is set. Is this expected?

$ TERM=dumb node
Welcome to Node.js v12.8.0.
Type ".help" for more information.
>
[press ^C]
(To exit, press ^C again or ^D or type .exit)
[press ^C]
>
[press ^D]
>
[press ^D]
>.exit
[finally out of it]

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    on Aug 13, 2019
  2. bnoordhuis commented on Aug 13, 2019

    @bnoordhuis
    Member

    I don't think it's unexpected: the terminfo entry for 'dumb' basically says it doesn't support anything except ^G (bel).

    On the other hand, lib/readline.js has some emulation baked in and teaching it about ^D isn't hard:

    diff --git a/lib/readline.js b/lib/readline.js
    index b741557a4d..1e7047ce1d 100644
    --- a/lib/readline.js
    +++ b/lib/readline.js
    @@ -825,6 +825,9 @@ function _ttyWriteDumb(s, key) {
         }
       }
     
    +  if (key.ctrl && key.name === 'd')
    +    this.close();
    +
       switch (key.name) {
         case 'return':  // Carriage return, i.e. \r
           this._sawReturnAt = Date.now();

    The reason ^C doesn't work is because the first ^C leaves a \x03 character (the C in ^C) in the command buffer and that trips up this logic:

    node/lib/repl.js

    Lines 633 to 638 in 427e534

    const empty = self.line.length === 0;
    self.clearLine();
    _turnOffEditorMode(self);
    const cmd = self[kBufferedCommandSymbol];
    if (!(cmd && cmd.length > 0) && empty) {

  3. cjihrig commented on Aug 14, 2019

    @cjihrig
    Contributor

    This change in _ttyWriteDumb() fixes the Control+C issue. I'm not sure if it's correct.

    diff --git a/lib/readline.js b/lib/readline.js
    index b741557a4d..0606b63585 100644
    --- a/lib/readline.js
    +++ b/lib/readline.js
    @@ -823,6 +823,8 @@ function _ttyWriteDumb(s, key) {
           // This readline instance is finished
           this.close();
         }
    +
    +    return;
       }
     
       switch (key.name) {

    And, like Ben mentioned, the code doesn't currently support Control+D. It looks like it was never added in the original PR.

  4. legendecas commented on Aug 14, 2019

    @legendecas
    Member

    Control+D would trigger end of stdin stream in most terminal, which has handled by readline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions