Poison Ivy

Joined: 14 Feb 2005 Posts: 171 Location: Robinson Park
|
Posted: Fri Jul 01, 2005 7:11 pm Post subject: quick+dirty RP log highlighter |
|
|
This was tested with logs from the tinyFugue (tf) MUSH client, but should work with most sane log formats.
As-is, it expects individual poses to be paragraphs ((multi-line?) pose, empty line, next person's (multi-line?) pose), but it can be changed to expect one (possibly very long) line per pose (with no empty lines between poses) by inserting a # at a given location (see source).
Use like so: ./whateverYouSavedThisScriptAs myLog > myFunkyFormattedLog
| Code: |
#!/usr/bin/perl --
use strict;
## read a log of a role-playing session generated by the tinyFugue (tf)
## MUSH/MUD client, clean it, and and highlight it using standard bulletin
## board markup.
##
## --Poison Ivy @ Gotham Knights
## 2005/02/15 basics
## 2005/02/17 support *markup*
## 2005/02/18 support -markup-
## 2005/03/26 allow / (for italics) within quoted text
## 2005/04/02 don't detect / (for italics) in [/x] from previous substitution
## 2005/04/04 multi-detect / (for italics) in ""
## 2005/06/12 recognize <Phone>, have colour configurables in preamble
## 2005/07/02 fix a bug with -emphasis-
## read in paragraph mode -- this is necessary if the client word-wraps the
## logs; if it doesn't and one pose is one line in the log (regardless of
## length), put a # in front of the following line to disable it:
$/='';
my %cols = ( 'OOC' => 'darkred',
'desc' => 'darkred',
'page' => 'green',
'channel' => 'olive',
'dialog' => 'darkblue' );
## no user-configurables after this point.
## ----------------------------------------------------------------------------
## no previous paragraph yet, set to empty string
my $p="";
## line counter
my $c=0;
while(<>) {
## removing trailing newlines
chomp;
chomp;
## remove line-breaks in the middle of poses/paragraphs
s/\n/ /sg;
## remove extra spaces
s/\s{2,}/ /g;
s/^(.*?)[\t ]+$/$1/g;
## if this paragraph is a duplicate of the previous one, discard it
if ( $p eq $_ ) {
next; }
## technical feedback from the game server
if ( $_ =~ m/^GAME: .*$/ ) {
next; }
if ( $_ =~ m/^Huh\? \(Type "help" for help\.\)/ ) {
next; }
## output multi-descer ("You changed your description")
if ( $_ =~ m/^Excellent choice!/ ) {
next; }
## remember this paragraph so we can catch duplicates
$p=$_;
## make log title (first non-empty line in log) bold
if($c==0) {
s-(.*)-[b]${1}[/b]-; }
## HANDLE MARKUP
## _underline_ -> [u]underline[/u]
s-_([^_]+?)_-[u]${1}[/u]-g;
## "/italics/" -> "[u]italics[/u]" (in quoted text)
while(m-"(|((.*)[^\[]))/([^/"]*)([^\[])/(.*)"-) {
s-"(|((.*)[^\[]))/([^/"]*)([^\[])/(.*)"-"${1}[u]${4}${5}[/u]${6}"-g; }
## /italics/ -> [i]italics[/i] (in narration)
s-([^\[])/([^/]+?)([^\[])/-${1}[i]${2}${3}[/i]-g;
s-^/([^/]+?)([^\[])/-${1}[i]${2}${3}[/i]-g;
## -strikethru- -> [u]strikethru[/u]
s&\s-+(\w+?)-\s+& [u]${1}[/u] &g;
## *bold* -> [b]bold[/b]
s-\*+([^*]+?)\*+-[b]${1}[/b]-g;
## HANDLE ENTITIES
## -- -> —
# s/-{2,}/—/g;
## HIGHLIGHT BY COMMUNICATION TYPE
## paging (long distance communication)
if ( $_ =~ m/^.* pages[^:]*: .*/ ) {
print "[color=".$cols{'page'}."]".$_."[/color]\n\n"; }
elsif ( $_ =~ m/^You paged .* with .*/ ) {
print "[color=".$cols{'page'}."]".$_."[/color]\n\n"; }
elsif ( $_ =~ m/^Long distance to [^:]*: .*/ ) {
print "[color=".$cols{'page'}."]".$_."[/color]\n\n"; }
elsif ( $_ =~ m/^From afar.*, .*/ ) {
print "[color=".$cols{'page'}."]".$_."[/color]\n\n"; }
## Out Of Character (stage direction)
elsif ( $_ =~ m/^\<OOC\>\s.*/ ) {
print "[color=".$cols{'OOC'}."]".$_."[/color]\n\n"; }
## room and other descriptions
elsif ( $_ =~ m/^\{(.*)\}$/ ) {
print "[color=".$cols{'desc'}."]".$1."[/color]\n\n"; }
## channels (MUSH-wide public conversation)
elsif (!( $_ =~ m/^\<Phone\> .*/ ) && ( $_ =~ m/^\<\w+\> .*/ )) {
# print "[color=".$cols{'channel'}."]".$_."[/color]\n\n";
}
## the actual play
else {
s-"([^"]+)"-[i][color=$cols{'dialog'}]"$1"[/color][/i]-g;
print $_."\n\n"; }
$c++; }
|
The equally quick'n'dirty setup for tinyFugue to produce a similar highlight while you play works like so (you'll hate the colours, replace al gusto):
| Code: |
/def -F -mregexp -wGK -p6 -t"(.*?)(\*.+?\*)(.*?)" -P2h em_star
/def -F -mregexp -wGK -p6 -t"(.*?)[ \"](\/.+?\/)[\?!\. \"](.*?)" -P2h em_slash
/def -F -mregexp -wGK -p6 -t"(.*?)(_\w+?_)(.*?)" -P2h em_under
/def -F -mregexp -wGK -p6 -t"(.*?)[ \"](-\w+?-)[\?!\. \"](.*?)" -P2h em_hyphen
/def -F -mregexp -wGK -p5 -t"(.*?)(\".*?\")(.*?)" -P1n;2Ccyan;Rn quotes
/def -mregexp -wGK -p1 -t"^\<OOC\> .*" -P0Cred ooc
/def -mregexp -wGK -p4 -t"^\<Phone\> .*" -P0Cbgblue phone
/def -mregexp -wGK -p3 -t"^\<.*\> .*" -P0Cbgred channel
/def -mregexp -wGK -p4 -t"^.* pages[^:]*: .*" -P0Cbgyellow page_fm
/def -mregexp -wGK -p4 -t"^You paged .* with .*" -P0Cbgyellow page_to
/def -mregexp -wGK -p4 -t"^From afar.*, .*" -P0Cbgyellow page_pose_fm
/def -mregexp -wGK -p4 -t"^Long distance to [^:]*: .*" -P0Cbgyellow page_pose_to
|
Note that this limits the highlights to a world named "GK" -- if you used a different name for Gotham Knights in your /addworld statement, change the -wGK particle (or eliminate it altogether to apply the macros to any MUSH).
Paste them into tinyFugue to try them out, or add them to the .tfrc file in your home to make them permanent. |
|