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

Add west --color=always and west config color=always #651

Open
marc-hb opened this issue Apr 18, 2023 · 3 comments
Open

Add west --color=always and west config color=always #651

marc-hb opened this issue Apr 18, 2023 · 3 comments

Comments

@marc-hb
Copy link
Collaborator

marc-hb commented Apr 18, 2023

Git has an (somewhat inconsistent) set of "color = always" options to override the automated terminal detection. Demo of one of the (too many) options:

git diff                            # colored           :-)
git diff                | less      # not colored       :-(
git diff --color=always | less  -R  # colored again!    :-(

It would nice for west to offer the same feature.

While rarer, color=never is sometimes needed too. For instance some CI engines try hard to pretend they are terminals to capture colors but then can fail to display them for some reason.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Apr 18, 2023

Originally posted by @marc-hb in #649 (comment)

In west, colorama handles terminal detection. The following and BARELY TESTED hack seems equivalent to color=always

--- a/src/west/app/main.py
+++ b/src/west/app/main.py
@@ -895,7 +895,7 @@ def main(argv=None):
 
     # Makes ANSI color escapes work on Windows, and strips them when
     # stdout/stderr isn't a terminal
-    colorama.init()
+    colorama.init(strip=False)
 
     # Create the WestApp instance and let it run.
     app = WestApp()
west diff | less -R # color!
west diff | less    # as expected, color mojikabe :-(

@marc-hb
Copy link
Collaborator Author

marc-hb commented Apr 18, 2023

An interesting question design is: when git and west settings conflict, which one wins?

git config color.ui never
west config color always

west diff | less -R # color or not?

To make things even more interesting, git has not just one color.ui setting but also another color.status and who knows what else.

@marc-hb
Copy link
Collaborator Author

marc-hb commented Apr 21, 2023

Spotted by @mbolivar-nordic:

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

1 participant