forked from oppiliappan/statix
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Disable colored output when NO_COLOR env is present #1781
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
Open
prashantrahul141
wants to merge
4
commits into
molybdenumsoftware:master
Choose a base branch
from
prashantrahul141:feat/no-color
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c51bb71
feat: Dont use colors when NO_COLOR env is present
prashantrahul141 57ad76c
docs: Add color toggle ability via NO_COLOR env to readme
prashantrahul141 a48f092
feat(test): Ability to disable stripping ansi escape, and pass env vars
prashantrahul141 a8b3e02
feat(test): introduce no_color tests with snapshots
prashantrahul141 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| mod _utils; | ||
|
|
||
| use crate::_utils::OutputProcessing; | ||
| use std::collections::HashMap; | ||
|
|
||
| const EXPR: &'static str = "let in null"; | ||
|
|
||
| #[test] | ||
| fn test_output_with_color_ansi_escape() { | ||
| let stdout = _utils::test_cli( | ||
| EXPR, | ||
| &["check"], | ||
| HashMap::new(), | ||
| OutputProcessing::Unchanged, | ||
| ) | ||
| .unwrap(); | ||
| let snapshot = format!("{EXPR}\n---\n{stdout}"); | ||
| insta::with_settings!({omit_expression => true}, { | ||
| insta::assert_snapshot!("output_with_color_ansi_escape", snapshot); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_output_without_color_ansi_escape() { | ||
| let stdout = _utils::test_cli( | ||
| EXPR, | ||
| &["check"], | ||
| HashMap::from([("NO_COLOR", "1")]), | ||
| OutputProcessing::Unchanged, | ||
| ) | ||
| .unwrap(); | ||
| let snapshot = format!("{EXPR}\n---\n{stdout}"); | ||
| insta::with_settings!({omit_expression => true}, { | ||
| insta::assert_snapshot!("output_without_color_ansi_escape", snapshot); | ||
| }); | ||
| } |
12 changes: 12 additions & 0 deletions
12
bin/tests/snapshots/no_color__output_with_color_ansi_escape.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| source: bin/tests/no_color.rs | ||
| --- | ||
| let in null | ||
| --- | ||
| [33m[W02] Warning:[0m Useless let-in expression | ||
| [38;5;246m╭[0m[38;5;246m─[0m[38;5;246m[[0m<temp_file_path>:1:1[38;5;246m][0m | ||
| [38;5;246m│[0m | ||
| [38;5;246m1 │[0m [35ml[0m[35me[0m[35mt[0m[35m [0m[35mi[0m[35mn[0m[35m [0m[35mn[0m[35mu[0m[35ml[0m[35ml[0m | ||
| [38;5;246m ·[0m [35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m┬[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m | ||
| [38;5;246m ·[0m [35m╰[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m[35m─[0m This let-in expression has no entries | ||
| [38;5;246m───╯[0m |
12 changes: 12 additions & 0 deletions
12
bin/tests/snapshots/no_color__output_without_color_ansi_escape.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| source: bin/tests/no_color.rs | ||
| --- | ||
| let in null | ||
| --- | ||
| [W02] Warning: Useless let-in expression | ||
| ╭─[<temp_file_path>:1:1] | ||
| │ | ||
| 1 │ let in null | ||
| · ─────┬───── | ||
| · ╰─────── This let-in expression has no entries | ||
| ───╯ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.