Skip to content

Instantly share code, notes, and snippets.

@yath
Created June 24, 2018 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yath/ad991761258ca9d69a99839066e68323 to your computer and use it in GitHub Desktop.
Save yath/ad991761258ca9d69a99839066e68323 to your computer and use it in GitHub Desktop.
#!/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