Skip to content

Instantly share code, notes, and snippets.

@aaron-em
Created December 2, 2016 19:31
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 aaron-em/15bb676f2e694bff209aeb217dee459e to your computer and use it in GitHub Desktop.
Save aaron-em/15bb676f2e694bff209aeb217dee459e to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use constant EOT => chr(4);
use constant BEL => chr(7);
use constant ESC => chr(27);
sub get_term_fontsize {
local $|=1;
my $oldstty = `stty -g`;
my $resp;
my $size;
system('stty raw -echo min 0');
print ESC . "]7770;?" . BEL;
system("stty $oldstty");
sysread(STDIN, $resp, 9);
$resp =~ m@;(\d+)@;
$size = $1;
return $size;
};
sub print_sample_sixel_image {
print ESC . "Pq";
print "#0;2;0;0;0#1;2;100;100;100#2;2;80;80;80\n";
print "#1??}}GG}}??}}??--\n";
for (my $j = 0; $j < 2; $j++) {
my $last = 0;
for (my $i = 0; $i <= 12; $i++) {
my $reg = rand(2) + 1;
print "#" . ($last % 2 ? 1 : 2);
print chr(63 + (1 << $last));
$last += 1;
$last = $last % 6;
};
print "-\n"; # end with '-' to break the line
};
print ESC . "\\";
};
print "Current terminal font size is " . get_term_fontsize() . "\n";
print_sample_sixel_image();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment