83 lines
1.4 KiB
Perl
83 lines
1.4 KiB
Perl
|
|
#!/usr/bin/env perl
|
||
|
|
#
|
||
|
|
# txt_console_to_html.pl
|
||
|
|
#
|
||
|
|
# Example:
|
||
|
|
# chmod +x txt_console_to_html.pl
|
||
|
|
# ./txt_console_to_html.pl 20260518_1855_zerodev2_Gate2F_BilateralConstitution_90seconds.txt
|
||
|
|
#
|
||
|
|
# Subversion:
|
||
|
|
# $Id$
|
||
|
|
# $HeadURL$
|
||
|
|
#
|
||
|
|
|
||
|
|
use strict;
|
||
|
|
use warnings;
|
||
|
|
use File::Basename qw(basename);
|
||
|
|
use POSIX qw(strftime);
|
||
|
|
|
||
|
|
my $infile = shift or die "Usage: $0 console_capture.txt\n";
|
||
|
|
|
||
|
|
open my $in, '<:encoding(UTF-8)', $infile
|
||
|
|
or die "Cannot open $infile: $!\n";
|
||
|
|
|
||
|
|
my $text = do { local $/; <$in> };
|
||
|
|
close $in;
|
||
|
|
|
||
|
|
my $base = basename($infile);
|
||
|
|
$base =~ s/\.[^.]+$//;
|
||
|
|
|
||
|
|
my $timestamp = strftime('%Y%m%d_%H%M%S', localtime);
|
||
|
|
my $outfile = "${base}_console_${timestamp}.html";
|
||
|
|
|
||
|
|
$text =~ s/&/&/g;
|
||
|
|
$text =~ s/</</g;
|
||
|
|
$text =~ s/>/>/g;
|
||
|
|
|
||
|
|
open my $out, '>:encoding(UTF-8)', $outfile
|
||
|
|
or die "Cannot write $outfile: $!\n";
|
||
|
|
|
||
|
|
print $out <<"HTML";
|
||
|
|
<!DOCTYPE html>
|
||
|
|
<!--
|
||
|
|
Created by: txt_console_to_html.pl
|
||
|
|
Date: $timestamp
|
||
|
|
Source file: $infile
|
||
|
|
\$Id\$
|
||
|
|
\$HeadURL\$
|
||
|
|
-->
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<title>$base</title>
|
||
|
|
<style>
|
||
|
|
html, body {
|
||
|
|
margin: 0;
|
||
|
|
padding: 0;
|
||
|
|
background: #111;
|
||
|
|
color: #eee;
|
||
|
|
}
|
||
|
|
|
||
|
|
body {
|
||
|
|
padding: 10px;
|
||
|
|
font-family: "DejaVu Sans Mono", "Liberation Mono", "Courier New", monospace;
|
||
|
|
font-size: 13px;
|
||
|
|
line-height: 1.25;
|
||
|
|
white-space: pre;
|
||
|
|
}
|
||
|
|
|
||
|
|
.console-title {
|
||
|
|
color: #9fd7ff;
|
||
|
|
font-weight: bold;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body><span class="console-title">$base</span>
|
||
|
|
|
||
|
|
$text</body>
|
||
|
|
</html>
|
||
|
|
HTML
|
||
|
|
|
||
|
|
close $out;
|
||
|
|
|
||
|
|
print "Wrote: $outfile\n";
|