Skip to content

Angular CLI can't tell when stdout isn't a TTY, always outputs ANSIΒ #17053

Closed
@ocket8888

Description

@ocket8888

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

No

Description

The Angular CLI always outputs ANSI control codes to colorize output, regardless of whether or not the process's STDOUT is a TTY, and offers no option to forcibly override that behavior. This makes the output difficult/impossible (depending on the command) to parse without passing it through a filter to first strip out all of the ANSI characters.

I'm opening this as a bug - not a feature request - because #6478 has been closed without a "wontfix" label, indicating the intended behavior is that this problem has been solved.

πŸ”¬ Minimal Reproduction

Run any command in any environment with any passed option-arguments or "flags", observe colorized output.

πŸ”₯ Exception or Error

Here's some sample output when an ng build results in an error - thus producing a lot of colorized output:


chunk {main} main.js, main.js.map (main) 628 bytes [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 122 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 11 kB [initial] [rendered]
Date: 2020-02-22T20:31:55.400Z - Hash: f4ca5d6cd60b894262e5 - Time: 5043ms

ERROR in οΏ½[96msrc/app/app.component.tsοΏ½[0m:οΏ½[93m28οΏ½[0m:οΏ½[93m50οΏ½[0m - οΏ½[91merrorοΏ½[0mοΏ½[90m TS2339: οΏ½[0mProperty 'entities' does not exist on type 'EntitiesService'.

οΏ½[7m28οΏ½[0m  	const id = `${Object.keys(this.entitiesService.entities).length}-${(new Date()).getTime()}`;
οΏ½[7m  οΏ½[0m οΏ½[91m 	                                               ~~~~~~~~οΏ½[0m
οΏ½[96msrc/app/app.component.tsοΏ½[0m:οΏ½[93m29οΏ½[0m:οΏ½[93m24οΏ½[0m - οΏ½[91merrorοΏ½[0mοΏ½[90m TS2339: οΏ½[0mProperty 'entities' does not exist on type 'EntitiesService'.

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.3.23
Node: 13.7.0
OS: linux x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router

Package                                    Version
--------------------------------------------------------------------
@angular-devkit/architect                  0.803.23
@angular-devkit/build-angular              0.803.23
@angular-devkit/build-optimizer            0.803.23
@angular-devkit/build-webpack              0.803.23
@angular-devkit/core                       8.3.23
@angular-devkit/schematics                 8.3.23
@angular/cli                               8.3.23
@ngtools/webpack                           8.3.23
@nguniversal/express-engine                8.2.6
@nguniversal/module-map-ngfactory-loader   8.2.6
@schematics/angular                        8.3.23
@schematics/update                         0.803.23
rxjs                                       6.5.4
typescript                                 3.5.3
webpack                                    4.39.2
I can't imagine why this would matter, but find enclosed my system information

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ bwilli415@manjaro
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ OS: Manjaro 18.1.5 Juhraya
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Kernel: x86_64 Linux 5.3.18-1-MANJARO
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Uptime: 21d 20h 9m
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Packages: 1440
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Shell: zsh 5.7.1
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Resolution: 1920x1080
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ DE: GNOME 3.34.2
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ WM: Mutter
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ WM Theme: Matcha-sea
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ GTK Theme: Matcha-dark-sea [GTK2/3]
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Icon Theme: Papirus-Dark-Maia
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Font: Noto Sans 11
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ Disk: 211G / 399G (56%)
CPU: Intel Core i7-7600U @ 4x 3.9GHz [53.0Β°C]
GPU: Mesa DRI Intel(R) HD Graphics 620 (Kaby Lake GT2)
RAM: 5669MiB / 15893MiB

Anything else relevant?
I have some recommendations on how to solve this.

I'd recommend the widely used --color/--no-color mutually exclusive option-arguments be added to the base ng command, so that it'd be immediately supported by all sub-commands and making it trivial to set alias ng="ng --color" or alias ng="ng --no-color" in environments where that's desirable.

I'd also suggest that support be added for the NO_COLOR environment variable which has found some wide adoption in recent years.

Finally, the default behavior when no overriding option-arguments or execution environment variables should be to display colors if and only if it can be determined that STDOUT refers to a TTY.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions