Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coloring should be disabled if output is not a TTY #21

Closed
meowgorithm opened this issue Nov 25, 2019 · 10 comments · Fixed by #22
Closed

Coloring should be disabled if output is not a TTY #21

meowgorithm opened this issue Nov 25, 2019 · 10 comments · Fixed by #22
Labels
enhancement New feature or request

Comments

@meowgorithm
Copy link
Member

It's sort of opposite the point of this library, but with things like the auto-fetch-from-github functionality users could find themselves doing something like the following:

gold -s dark.json https://github.com/muesli/beehive | less

…which of course would appear littered with ASCII escape codes.

@muesli
Copy link
Contributor

muesli commented Nov 25, 2019

Good point, let me fix that.

@CallumHoward
Copy link

Could this have an optional flag to force colors? I would like to use glow to preview markdown files in ranger but the colours get stripped.

@muesli
Copy link
Contributor

muesli commented Dec 31, 2019

@CallumHoward You can explicitly set a style to enforce it: glow -s dark | less -r for example.

@CallumHoward
Copy link

Amazing, thanks!

@eric-saintetienne
Copy link

eric-saintetienne commented Sep 19, 2024

That's not the same output though.

With -s dark I get this output:

But when -s dark stdout is piped I get a different output (I used cat but it's the same with less, even with the -R argument):

I've tried to force stdout being a tty through unbuffer (part of the expect package) which provides a tty to stdout but then the behaviour is terrible: glow takes about 10 seconds to complete and extra garbage is output.

In summary, there's something wrong with the implementation of how tty is handled:

  1. using a style doesn't render the same output when a tty is present (or not)
  2. glow takes a very long time to complete and outputs extra garbage when a tty is emulated via unbuffer.

@eric-saintetienne
Copy link

@muesli can you please re-open this ticket? Thanks.

@meowgorithm
Copy link
Member Author

Hey everyone. I can look into this one. This is the same issue as #654, right? If so, let’s track it there.

@eric-saintetienne
Copy link

Yes it seems to be the same issue. The ticket #654 is more recent but that shouldn't be an issue as the current ticket is closed.

Thanks for looking into it.

@meowgorithm
Copy link
Member Author

Awesome, sounds good. Let’s track the issue there, then.

@nikelborm
Copy link

nikelborm commented Nov 11, 2024

I also made my ugly hack to force colors

Also takes a lot of time to do something, but at least I was able to remove the garbage:

script -q -c "glow README.md" | tail -n +2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants