Skip to content

The isatty check is always done on stdout, even if the output file is different #41

@avdstaaij

Description

@avdstaaij

It seems that termcolor always checks sys.stdout for being a TTY, instead of the file you are actually outputting to.
A consequence of this is that termcolor will not color output to sys.stderr when a program is used in a pipe. This is an unfortunate limitation.

It makes sense that colored always checks sys.stdout, since it has no way of knowing what the output file will be. However, I would like to request there to be some way of explicitly specifying the intended output file, perhaps via an optional output_file argument.

For cprint, this is arguably a bug. I believe it could be fixed by looking for the file argument in kwargs and then checking that instead of sys.stdout.

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