-
Notifications
You must be signed in to change notification settings - Fork 363
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
When output is redirected, terminal capabilities are ignored and colors are illegible #654
Comments
It's the behavior of In short, when being piped, it detects that no terminal capabilities are available, hence no color profile will be chosen. If you force the color output with |
Aha, there we have it. Technically speaking Alternatively, we could introduce a flag like
|
instead of the |
That’s fine by me, but |
script -q -c "glow README.md" | tail -n +2 |
After some digging, I found something interesting. bash -c "echo date_before_script: \$(date); script -q -c 'echo date_before_glow: \$(date); glow README.md; echo date_after_glow: \$(date)' > temp; cat temp; echo date_after_script: \$(date)" > temp2 Instead of with following README.md: # header
1. _something_
2. *bold*
temp2 looks like this:
Pairs of dates are exactly the same. Long execution is glow's or some other internally used library's responsibility. And for me it's always exactly 15 f***ing seconds. TTY is allocated immediately. And first line, that breaks output, is printed by glow too. @eric-saintetienne (pinging because I think you'll be interested about it too because you did the same stuff here: #21 (comment)) I tried tracing the program. I created following script: #!/bin/bash
/bin/bash -c "echo date_before_script: \$(/sbin/date); /sbin/script -q -c 'echo date_before_glow: \$(/sbin/date); SHLVL=1 COLUMNS=180 LINES=49 /sbin/glow README.md; echo date_after_glow: \$(/sbin/date)' > temp; /sbin/cat temp; echo date_after_script: \$(/sbin/date)" > temp2 And then I'm running it sudo strace ./sh What I get trace log
The most important part is where and how it hangs:
it hangs in this state with uncompleted line for 15 seconds. Here's the most interesting part. remember the trash line? Its three equal parts ( That's how stuff appears in a
Based on that, I conclude that it hangs each time AFTER it printed Also interesting observation:
Guess how long it executes?
I tried to decode this ANSI code using this cheatsheet and this character inspector. And probably this artifitial TTY takes too long to respond and is being cutoff on timeout? 🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️🤷🏻♀️ Also I have a hypothesis about what's up with all the trash symbols being triggered by printing Ideas? |
Until the fix is made somewhere, you can just use bat --style=plain --color=always "$file" |
My findings didn't end there. I tried to create new theme based on https://github.com/charmbracelet/glamour/blob/master/styles/dark.json and run it with new theme. I changed all margin fields from Timing improved. Now it runs 5 seconds faster. Beforetime /bin/bash -c "echo date_before_script: \$(/sbin/date); /sbin/script -q -c 'echo date_before_glow: \$(/sbin/date); SHLVL=1 COLUMNS=180 LINES=49 /sbin/glow README.md; echo date_after_glow: \$(/sbin/date)' > temp; /sbin/cat temp; echo date_after_script: \$(/sbin/date)" > temp2
cat temp2 | sed '3d'
3rd line:
Aftertime /bin/bash -c "echo date_before_script: \$(/sbin/date); /sbin/script -q -c 'echo date_before_glow: \$(/sbin/date); SHLVL=1 COLUMNS=180 LINES=49 /sbin/glow -s ./mystyle.json README.md; echo date_after_glow: \$(/sbin/date)' > temp; /sbin/cat temp; echo date_after_script: \$(/sbin/date)" > temp2
cat temp2 | sed '3d'
3rd line:
Edited theme: {
"document": {
"block_prefix": "\n",
"block_suffix": "\n",
"color": "252",
"margin": 0
},
"block_quote": {
"indent": 1,
"indent_token": "│ "
},
"paragraph": {},
"list": {
"level_indent": 2
},
"heading": {
"block_suffix": "\n",
"color": "39",
"bold": true
},
"h1": {
"prefix": " ",
"suffix": " ",
"color": "228",
"background_color": "63",
"bold": true
},
"h2": {
"prefix": "## "
},
"h3": {
"prefix": "### "
},
"h4": {
"prefix": "#### "
},
"h5": {
"prefix": "##### "
},
"h6": {
"prefix": "###### ",
"color": "35",
"bold": false
},
"text": {},
"strikethrough": {
"crossed_out": true
},
"emph": {
"italic": true
},
"strong": {
"bold": true
},
"hr": {
"color": "240",
"format": "\n--------\n"
},
"item": {
"block_prefix": "• "
},
"enumeration": {
"block_prefix": ". "
},
"task": {
"ticked": "[✓] ",
"unticked": "[ ] "
},
"link": {
"color": "30",
"underline": true
},
"link_text": {
"color": "35",
"bold": true
},
"image": {
"color": "212",
"underline": true
},
"image_text": {
"color": "243",
"format": "Image: {{.text}} →"
},
"code": {
"prefix": " ",
"suffix": " ",
"color": "203",
"background_color": "236"
},
"code_block": {
"color": "244",
"margin": 0,
"chroma": {
"text": {
"color": "#C4C4C4"
},
"error": {
"color": "#F1F1F1",
"background_color": "#F05B5B"
},
"comment": {
"color": "#676767"
},
"comment_preproc": {
"color": "#FF875F"
},
"keyword": {
"color": "#00AAFF"
},
"keyword_reserved": {
"color": "#FF5FD2"
},
"keyword_namespace": {
"color": "#FF5F87"
},
"keyword_type": {
"color": "#6E6ED8"
},
"operator": {
"color": "#EF8080"
},
"punctuation": {
"color": "#E8E8A8"
},
"name": {
"color": "#C4C4C4"
},
"name_builtin": {
"color": "#FF8EC7"
},
"name_tag": {
"color": "#B083EA"
},
"name_attribute": {
"color": "#7A7AE6"
},
"name_class": {
"color": "#F1F1F1",
"underline": true,
"bold": true
},
"name_constant": {},
"name_decorator": {
"color": "#FFFF87"
},
"name_exception": {},
"name_function": {
"color": "#00D787"
},
"name_other": {},
"literal": {},
"literal_number": {
"color": "#6EEFC0"
},
"literal_date": {},
"literal_string": {
"color": "#C69669"
},
"literal_string_escape": {
"color": "#AFFFD7"
},
"generic_deleted": {
"color": "#FD5B5B"
},
"generic_emph": {
"italic": true
},
"generic_inserted": {
"color": "#00D787"
},
"generic_strong": {
"bold": true
},
"generic_subheading": {
"color": "#777777"
},
"background": {
"background_color": "#373737"
}
}
},
"table": {},
"definition_list": {},
"definition_term": {},
"definition_description": {
"block_prefix": "\n🠶 "
},
"html_block": {},
"html_span": {}
} It is definitely faster and definitely because of reducing amount of escape sequences which are being attempted to be printed by glow. |
Next I'm gonna look for how |
Describe the bug
When output is redirected/piped, terminal capabilities are ignored and colors are illegible.
Setup
To Reproduce
README.md
. . .$ CLICOLOR_FORCE=1 glow --style dark README.md | head
Source Code
Sample README
Expected behavior
The colors should be the same as they are when
| head
is omitted, and the header titles should have enough contrast to be easily read.Screenshots
Additional context
See discussion at #440 (comment)
The text was updated successfully, but these errors were encountered: