Skip to content

Nodejs STILL sends ANSI escape sequences to dumb terminals. #26187

Description

@j3pic

My problem is described here: nodejs/node-v0.x-archive#5344

The only difference is I'm running the latest version of Node in 2019, presumably after patches have been applied that were supposed to have fixed the problem.

I'm running the REPL from the command line in an Emacs *shell* buffer. I have $NODE_DISABLE_COLORS set to 1, which doesn't matter because the �[3G escape sequence isn't a color code (those end in m).

#2712 doesn't look like it fixes the problem. That seems to just be the implementation of the $NODE_DISABLE_COLORS option.

Activity

  1. j3pic commented on Feb 18, 2019

    @j3pic
    Author

    As a workaround, I've created a C program to filter out the escape sequences. After compiling, you can invoke the Node REPL like this:

    node | noesc
    
    #include <stdio.h>
    #include <ctype.h>
    
    void
    throw_away()
    {
        for(int ch = fgetc(stdin); !feof(stdin) && !isalpha(ch); ch = fgetc(stdin));
    }
    
    main()
    {
        setbuf(stdin, NULL);
        setbuf(stdout, NULL);
        while(!feof(stdin)) {
            int ch = fgetc(stdin);
    	if(ch == '\033') throw_away();
    	else fputc(ch, stdout);
        }
    }
    
    
  2. mscdex commented on Feb 18, 2019

    @mscdex
    Contributor

    I can't duplicate this. If the output is a pipe or TERM=dumb is set, then REPL output is unstyled.

  3. j3pic commented on Feb 19, 2019

    @j3pic
    Author

    What is your stdout connected to? The escape sequences I'm seeing are for positioning the cursor, not styling the text, and they move the cursor to where it already is (just as seen in the original bug report), so if your stdout is a terminal that supports escape sequences there would be no visible effect. The REPL output would look unstyled.

  4. mscdex commented on Feb 19, 2019

    @mscdex
    Contributor

    Do you have a reproducible example, preferably without 3rd party modules?

  5. wlodzislav commented on Feb 22, 2019

    @wlodzislav
    Contributor

    I reproduced the behaviour, it's present when node is running in TTY .isTTY=true with TERM='dumb'.

    There are missing checks in console and repl. And no direct support for dumb terminals in readline.

    I made fix for the issue, with tests for each subsystem.

    I added explicit support for dumb terminals in readline(use _ttyWriteDumb).
    When TERM='dumb':

    • it doesn't use any ANSI escape codes for movement and output
    • it doesn't use color
    • it ignores all special keys except: escape, return and ctrl-c

    My PR: #26261

    About supported features of the dumb terminals:
    infocmp dumb
    wiki:Computer_terminal#Dumb_terminals

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions