File: vcsaview

package info (click to toggle)
hxtools 20251011-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,468 kB
  • sloc: ansic: 4,384; perl: 3,467; sh: 1,664; cpp: 353; makefile: 90
file content (40 lines) | stat: -rwxr-xr-x 777 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2004-2007 Jan Engelhardt
#
#	vcsaview - show Linux vt contents

use strict;

undef $/;
my $data   = join("", <>);
my $height = ord(substr($data, 0, 1));
my $width  = ord(substr($data, 1, 1));

for (my $y = 0; $y < $height; ++$y) {
	for (my $x = 0; $x < $width; ++$x) {
		my $p = 4 + 2 * ($y * $width + $x);
		print &attr2color(substr($data, $p+1, 1)),
		      substr($data, $p, 1);
	}
	print "\n";
}

sub asc2ans ()
{
	my $i = shift @_;
	return ($i &~ 5) | (($i & 1) ? 4 : 0) |	(($i & 4) ? 1 : 0);
}

sub attr2color ()
{
	my $char = ord shift @_;

	print "\e[0;";
	if ($char & 0x08) {
		print "1;";
	}
	print "4", &asc2ans(($char & 0x70) >> 4), ";";
	print "3", &asc2ans(($char & 0x07)), "m";
	return;
}