Skip to content

Color contamination fix - #1463

Closed
Akinwale Alagbe (hackean-msft) wants to merge 7 commits into
masterfrom
user/akalagbe/color-contamination-fix
Closed

Akinwale Alagbe (hackean-msft) wants to merge 7 commits into
masterfrom
user/akalagbe/color-contamination-fix

Conversation

@hackean-msft

@hackean-msft Akinwale Alagbe (hackean-msft) commented Sep 14, 2021 •

Copy link
Copy Markdown
Contributor

Reset console to default color when user force quits(hits ctrl + c twice) during execution.
Channel all console output write operations only through OutputStream/BaseStream wrappers.

Microsoft Reviewers: Open in CodeFlow

@github-actions

github-actions Bot commented Sep 14, 2021 •

Copy link
Copy Markdown

check-spelling-bot Report

Unrecognized words, please review:

  • Passif
Previously acknowledged words that are now absent ATL Globals IInstalled
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:microsoft/winget-cli.git repository
on the user/akalagbe/color-contamination-fix branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/winget-cli/issues/comments/918845633" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u

@github-actions

github-actions Bot commented Sep 14, 2021 •

Copy link
Copy Markdown

check-spelling-bot Report

Unrecognized words, please review:

  • Passif
Previously acknowledged words that are now absent ATL Globals IInstalled
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the [email protected]:microsoft/winget-cli.git repository
on the user/akalagbe/color-contamination-fix branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/winget-cli/issues/comments/918850226" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u


void BaseStream::Close()
{
m_enabled = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were a single shared object that every OutputStream had a reference to, at least m_enabled would need to be updated to be std::atomic_bool to prevent a race at Close.

@ghost ghost added the Needs-Author-Feedback Issue needs attention from issue or PR author label Sep 18, 2021
@ghost ghost removed the Needs-Author-Feedback Issue needs attention from issue or PR author label Sep 20, 2021

@JohnMcPMS JohnMcPMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that my casual use of the word "base" in a previous statement may have lead to this design, which I don't think is the right pattern. It is also bogged down by a lot of unnecessary name changes which make it a bit harder to see the actual functional changes.

My suggestion is to have the stream object that can be disabled as a singular member of the Reporter, replacing the current std::ostream m_out. That object is given out in place of the current m_out and treated almost identically otherwise. That keeps the code change minimal while achieving the goal of allowing all output to be disabled through a central mechanism.

{
case Level::Verbose:
result.AddFormat(TextFormat::Default);
m_vtOutputStream.AddFormat(TextFormat::Default);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may look like its working, but you are creating an ever expanding list of formats that must be output each time. It also will not work in the event of asynchronous operations (although we don't really have those at the moment, it would make having any harder in the future).

@ghost ghost added the Needs-Author-Feedback Issue needs attention from issue or PR author label Sep 24, 2021
@JohnMcPMS
JohnMcPMS deleted the user/akalagbe/color-contamination-fix branch October 7, 2021 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback Issue needs attention from issue or PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Color contamination to the console if the program was terminated by Ctrl+C

3 participants