glow icon indicating copy to clipboard operation
glow copied to clipboard

Table formatting breaks if output is piped

Open patrislav1 opened this issue 2 years ago • 1 comments

Describe the bug

Table formatting breaks when stdout is piped to a file or a program. glow seems to detect if stdout is connected to a tty, and leaves out some table formatting if it's not.

I would like to pipe glow output to tools like grep and fzf and still have the correct table formatting.

Setup Please complete the following information along with version numbers, if applicable.

  • OS [e.g. Ubuntu, macOS]: Ubuntu 22.04
  • Shell [e.g. zsh, fish]: zsh
  • Terminal Emulator [e.g. kitty, iterm]: kitty
  • Terminal Multiplexer [e.g. tmux]: Bug reproduces both with and without tmux
  • Locale [e.g. en_US.UTF-8, zh_CN.UTF-8, etc.]: en_US.UTF-8

To Reproduce Steps to reproduce the behavior:

$ glow test.md                                     

                                                                                                                    
    FIRST COLUMN │ SECOND COLUMN                                                                                      
  ───────────────┼────────────────                                                                                    
    Foo          │ Bar                                                                                                
                 │ Baz                                                                                                

$ glow test.md | cat                               


FIRST COLUMN │ SECOND COLUMN
───────────────┼────────────────
Foo          │ Bar
│ Baz

$ socat - EXEC:'glow test.md',pty,setsid,ctty | cat

                                                                            
    FIRST COLUMN │ SECOND COLUMN                                              
  ───────────────┼────────────────                                            
    Foo          │ Bar                                                        
                 │ Baz                                                        

Source Code Please include source code if needed to reproduce the behavior.

| First column | Second column |
|--------------|---------------|
| Foo          | Bar           |
|              | Baz           |

Expected behavior Table formatting should be maintained regardless of TTY presence.

Screenshots image

Additional context N/A

patrislav1 avatar Nov 28 '23 16:11 patrislav1

PS.: After reading main.go it turns out that this bug can be mitigated with explicit style option (e.g. -s dark)

OTOH, it can be reproduced without piping, by selecting the "notty" style

$ glow -s notty test.md     


FIRST COLUMN │ SECOND COLUMN
───────────────┼────────────────
Foo          │ Bar
│ Baz

patrislav1 avatar Nov 28 '23 17:11 patrislav1

yeah, I think this is on purpose since the output is not a TTY...

imho not a bug.

caarlos0 avatar Jul 10 '24 19:07 caarlos0

If output like this is on purpose, what would be the use case? (Genuine question). OTOH, what use case would break if the tables were correctly formatted even when not directly output to a TTY?

FIRST COLUMN │ SECOND COLUMN
───────────────┼────────────────
Foo          │ Bar
│ Baz

patrislav1 avatar Aug 01 '24 07:08 patrislav1