Last active
December 19, 2015 02:08
-
-
Save 2shortplanks/5880375 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env perl -s | |
| use strict; | |
| use warnings; | |
| use Term::ANSIColor qw(colored); | |
| $::r = $::r ? "" : '(?![\\x{1b}]\\[\\d+m)'; | |
| while (<>) { | |
| s{$::r([^\x{0a}\x{20}\x{21}-\x{7e}]+)}{ | |
| colored( | |
| join( | |
| "", | |
| map { | |
| '\\x{'. sprintf('%02x',ord($_)) . '}' | |
| } split(//, $1) | |
| ), | |
| 'yellow', | |
| ) | |
| }eg; | |
| } | |
| =head1 NAME | |
| bytey - a tool for showing non ascii bytes | |
| =head1 SYNOPSIS | |
| $ bytey somefile | |
| $ someprocess | bytey | |
| =head1 DESCRIPTION | |
| Renders non ASCII and I<invisible> bytes as yellow C<\x{...}> escape | |
| sequences (with the exception of C<\N{SPACE}> and C<\N{NEWLINE}> that | |
| are both rendered as is.) | |
| One exception to this: Escape codes for color sequences are NOT escaped. | |
| If you want to escape those as well, use the "-r" (raw) option. | |
| =head1 AUTHOR | |
| Written by Mark Fowler <[email protected]> | |
| =head1 COPYRIGHT | |
| Copyright Mark Fowler 2013. All Rights Reserved. | |
| This program is free software; you can redistribute it | |
| and/or modify it under the same terms as Perl itself. | |
| =cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment