Created
June 24, 2018 16:38
-
-
Save yath/ad991761258ca9d69a99839066e68323 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Term::Filter::Callback; | |
# SGR attributes to replacement value (or undef, if to be deleted). | |
my %sgrmap = ( | |
map { $_ => undef } 40..47, # set background color | |
37 => 30, # white => black | |
97 => 90, # bright white => bright black | |
); | |
# filter an SGR string (1;2;3;4;...). | |
sub filter_sgr { | |
return join(";", map { | |
exists $sgrmap{$_} ? ( | |
defined $sgrmap{$_} ? $sgrmap{$_} : ()) | |
: $_ | |
} split(";", $_[0])) | |
} | |
Term::Filter::Callback->new(callbacks => { | |
munge_output => sub { | |
my ($self, $text) = @_; | |
$text =~ s/\e\[([^m]+)m/"\e[".filter_sgr($1)."m"/ge; | |
$text; | |
}, | |
})->run("ssh", @ARGV); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment