anchore / syft

CLI tool and library for generating a Software Bill of Materials from container images and filesystems
Apache License 2.0
5.78k stars 531 forks source link

syft-table option adds escape chars at the end of each row #2915

Open paoloteti opened 1 month ago

paoloteti commented 1 month ago

What happened: Running: syft nats -o syft-table=out.txt

generate a text file with rows such as

NAME                               VERSION                             TYPE        
github.com/klauspost/compress      v1.17.8                             go-module    
github.com/minio/highwayhash       v1.0.2                              go-module    

Using syft nats --file=out.txt generate the same file without escape chars at the end of each row.

What you expected to happen: Files generated using syft nats -o syft-table=foo.txt to be the same of syft nats --file=foo.txt

Steps to reproduce the issue:

syft nats -o syft-table=out.txt
nano out.txt

Anything else we need to know?:

Environment:

tgerla commented 1 month ago

Hi @paoloteti, thanks for the report, we will look into the issue. In the meantime, if you set the environment variable NO_COLORS=y it will eliminate the control characters:

NO_COLORS=y syft nats -o syft-table=out.txt

Hope this helps!

wagoodman commented 1 month ago

To fix this, we could decorate the existing writers that are created when we process output flags with another writer that strips ANSI control characters from the stream of bytes being written.