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

Overlap between --style=auto and --decorations=auto is confusing #1743

Open
lilyball opened this issue Jul 21, 2021 · 0 comments
Open

Overlap between --style=auto and --decorations=auto is confusing #1743

lilyball opened this issue Jul 21, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@lilyball
Copy link

Describe the bug you encountered:

There's two different ways of specifying that decorations should not be displayed when the output is piped, and they both independently suppress the decorations. In particular, this is --style=auto and --decorations=auto. Both are documented as being the default (though it appears that --style=auto is not in fact the default, see #1742, possibly because of this issue). This is confusing as it means bat --style=full foo | cat omits decorations, and bat --style=auto --decorations=always foo | cat also omits decorations (this is more confusing if --style=auto is set in config, and so bat -f foo | cat will still omit decorations).

This is also frustrating if you want to turn off the auto style but aren't sure if the inherited style is actually auto or not. For example, bat --style=full -f foo | cat will ensure all decorations are on, but if my config includes --number then this will override that and turn on all decorations. Which is to say, there's no way to ensure decorations are visible without either knowing the current style or risking changing the style.

What did you expect to happen instead?

At the very least, bat needs to stop claiming --style=auto is the default, and it really should make it clear what the relationship is between --style and --decorations, and that saying --style=auto means --decorations=always isn't sufficient to print decorations when piped. This doesn't solve the problem of forcing auto decorations on though.

Also it looks like bat can actually mark some style components as auto and others as always, by writing this like --style=auto,numbers, such that bat --style=auto,numbers -f foo | cat will print numbers but printing to the terminal will display all decorations. This is undocumented, but is an argument against changing the actual meaning of --style=auto.

But I think we can also do something intelligent here by providing per-style-component control over auto behavior. We could allow for writing something like --style=numbers:auto,header (and then --style=auto just becomes the same thing as --style=full:auto), or perhaps a prefix sigil like --style=*numbers,header (or maybe some other sigil that doesn't need escaping from the shell). This doesn't solve the problem of "both style and decorations have independent auto toggles that stack", but it may make the fact that they stack a bit easier to understand (i.e. "--decorations=auto controls decorations when piping normally, but you can flag independent style components as auto if you want them to still be omitted when piping with -f").

Also I think we should find some way to make -ff force all auto-flagged styles as visible when piped. This way I can say -ff to means "no really, please pipe exactly the output I'd see at a terminal", such as if I want to capture the output to a file. Perhaps this could be done by adding another value --decorations=forced, and then -ff can add the --decorations=forced flag just like how -pp adds -pager=never.

How did you install bat?

Nix


bat version and environment

Software version

bat 0.18.0

Operating system

Darwin 20.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant