ble-reticulum/scripts/txt_console_to_html.pl

83 lines
1.4 KiB
Perl
Raw Normal View History

2026-05-19 09:44:03 -07:00
#!/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/&/&amp;/g;
$text =~ s/</&lt;/g;
$text =~ s/>/&gt;/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";