Description
π 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.