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

Force color output? #440

Closed
cwaldbieser opened this issue Jan 13, 2023 · 15 comments
Closed

Force color output? #440

cwaldbieser opened this issue Jan 13, 2023 · 15 comments

Comments

@cwaldbieser
Copy link

I'd like to use glow to preview markdown output in ranger-fm. However, it seems that when the output is sent to a pipe or redirected to a file, all the ansi codes are stripped off. This seems reasonable when you just want to save the output to a file or perform greps, etc. However, is there some flag to force the ansi codes to be retained?

@cwaldbieser
Copy link
Author

After poking around in the code, I noticed that if I explicitly set a style, it will be used regardless of whether or not we're writing to a terminal. That works, but you lose the ability to detect light vs. dark style.

@imericxu
Copy link

Setting -s auto worked for a bit but it just stopped working today and only the dark theme is being used (this is also for ranger btw).

@muesli
Copy link
Contributor

muesli commented Feb 22, 2023

-s auto is the default. You want to specify the actual theme, e.g. -s dark.

@imericxu
Copy link

Omitting -s in scope.sh just disables all colors. And I don't want it to always be dark; I set up my terminal to sync with my device light/dark theme. I don't know if this is an issue with ranger or glow, but bat detects light and dark fine everywhere.

@varon
Copy link

varon commented Jun 26, 2023

Make sure that COLORTERM is defined in your env-vars and set to truecolor

@Anomalocaridid
Copy link

It seems like when using a custom theme, I need to specify the theme every time I want to force color output. The ability to force color output would be very helpful and save me from having to hardcode the path to my custom theme I want in things like shell scripts and aliases rather than just specifying it once in glow's config file.

@caarlos0
Copy link
Member

caarlos0 commented Jul 3, 2024

you can force by setting CLICOLOR_FORCE=1, and in addition you might want to set COLORTERM=truecolor to have truecolor enabled as well.

@caarlos0 caarlos0 closed this as completed Jul 3, 2024
@AndydeCleyre
Copy link

This seems to be new behavior since 2.0 I guess, whereas previously specifying a style was enough to ensure use of that style when piped. IMO it's worth a note on the GH release item.

@AndydeCleyre
Copy link

Although it's using a different (less readable) color scheme when piped, even though the color scheme (dark) is specified on the command line.

image

AndydeCleyre added a commit to AndydeCleyre/dotfiles-zsh that referenced this issue Sep 6, 2024
@folliehiyuki
Copy link

Although it's using a different (less readable) color scheme when piped

This is because when terminal output is not detected, and CLICOLOR_FORCE=1 is set, termenv will use ANSI 4-bit color profile. See https://github.com/muesli/termenv/blob/82936c5ea257b458deb5238e6093773b42c43773/termenv.go#L104.

@AndydeCleyre
Copy link

Should it instead reuse the logic from https://github.com/muesli/termenv/blob/master/termenv_unix.go#L23 ? That checks TERM and COLORTERM as well as a list of known terminal emulators.

@mgnsk
Copy link

mgnsk commented Oct 9, 2024

I've also had this issue for some time now. Since 1407793, colors broke when glow is used as an fzf previewer.

Here's an example

Test file:

# _Italic title_

Script:

#!/usr/bin/env bash

function preview {
	# broken since commit 1407793
	# before commit 1407793, I was using this command:
	# glow --style=auto "$1"

	# half-broken since commit 1407793, italic text but no color
	# glow --style=dark "$1"

	# almost works since 1407793 but wrong colors
	export CLICOLOR_FORCE=1
	export COLORTERM=truecolor
	glow --style=dark "$1"
}

export -f preview

fzf --preview "bash -c 'preview {}'"

How it looked before with glow --style=auto "$1":
okay

How it looks now with CLICOLOR_FORCE=1 COLORTERM=truecolor glow --style=dark "$1":
broken

@meowgorithm
Copy link
Member

meowgorithm commented Oct 17, 2024

Oof, thanks for the heads up @AndydeCleyre and @mgnsk. This looks like a regression. Mind opening an issue accordingly?

@ostap-tymchenko
Copy link

Has anyone found any solutions? I'm trying to use glow for markdown editing via watch -c -n 1 CLICOLOR_FORCE=1 glow DOC.md --style dracula but I'm getting no luck. Just colorless output

@meowgorithm
Copy link
Member

Just a note that we're chatting about the issue here: #654.

@caarlos0 just a note that it looks like CLICOLOR_FORCE=1 COLORTERM=truecolor no longer work together.

emmanueltouzery added a commit to emmanueltouzery/nvim_config that referenced this issue Nov 13, 2024
glow2 broke color rendering when the output is redirected: charmbracelet/glow#440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests