compmstr
Joined: 05 Jul 2010 Posts: 17
|
Posted: Sat Jul 17, 2010 4:54 pm Post subject: Vertical split map/chats area |
|
|
This script adds a few aliases that allow you to have a 10x10 map with other output beside it in the top split.
You could also use it to set up some gauges or something in the "map" area.
Usage:
need to have a split of 11, 1
clearmap; - clears the map
addmapline <map text>; - adds a new line to the bottom of the map
addchatline <text>; - adds a new chat line, bottom displayed is most recent.
showtop; - displays both the map and chat lines at the top of the screen
Any comments would be welcome
| Code: |
#nop set up maplines and chatlines
#var maplines {};
#loop {1} {10} {cnt} {#list maplines insert 1 {};};
#var chatlines{};
#loop {1} {10} {cnt} {#list chatlines insert 1 {};};
#alias {clearmap}
{
#unvariable maplines;
#nop #echo {Clearing map}
#var maplines {};
#loop {1} {10} {cnt} {#list maplines insert 1 { };}
};
#alias {addmapline}
{
#nop each map line will be at most 10 visible chars
#nop #echo {Adding map line};
#list maplines ins -1 {%0};
#list maplines del 1;
};
#alias {addchatline}
{
#var newChatLine {};
#unvariable newChatLine;
#var newChatLine {%0};
#replace {newChatLine} {"%"} {"&perc;"};
#replace {newChatLine} {'} {'};
#format {scriptLine} {addChatLine.pl %C '$newChatLine'};
#script {$scriptLine};
};
#nop display the map and chat lines
#alias {showtop}
{
#loop {1} {10} {cnt}
{
#format {curString} {%-12s%s} {$maplines[$cnt]} {$chatlines[$cnt]};
#echo {{$curString} {-$cnt}};
};
};
|
*Edit: of course, it would help if I included the perl script for add chat lines *
| Code: |
#!/usr/bin/env perl
use Text::Wrap;
$screenCols = $ARGV[0];
$theText = $ARGV[1];
$theText =~ s/'/'/g;
$Text::Wrap::columns = $screenCols - 13;
open LOG, ">>chatline.log";
print LOG "\n\nNew run...\n";
print LOG "Columns: $screenCols\n";
print LOG "Text: $theText\n";
#take the ANSI sequences out of the text
#store in two lists, one of the indexes that they were found at, the other with
# the sequence itself
$curIndex = 0;
@indices = ();
@escapes = ();
$firstIndex = index($theText, "\x1b[");
$smallString = $theText;
while(1)
{
#find the last escape sequence
if($curIndex == 0 && $firstIndex == 0)
{
}
else
{
$curIndex = index($theText, "\x1b[", $curIndex);
}
#print "Index: $curIndex\n";
if($curIndex == -1)
{
last;
}
else
{
#find the first letter m at the end of it
$curEnd = index($theText, 'm', $curIndex + 1);
#print "End: $curEnd\n";
$curEscape = substr($theText, $curIndex, $curEnd - $curIndex + 1);
$escapeFind = quotemeta $curEscape; #escape regexp metachars
#print "Escape search: " . $escapeFind . "\n";
$smallString =~ s/$escapeFind//;
#print "Small String: ";
#print $smallString . "\n";
@indices = (@indices, $curIndex);
@escapes = (@escapes, $curEscape);
}
$curIndex += 1;
}
#print "Indices: " . @indices . "\n";
@lines = split /\n/, wrap("", "", $smallString);
$lineStart = 0;
$curIndex = 0;
foreach $line (@lines)
{
while($curIndex <= length(@indices) and $indices[$curIndex] < length($line))
{
substr($line, $indices[$curIndex], 0) = $escapes[$curIndex];
#print "Index: " . $indices[$curIndex] . "\n";
$curIndex += 1;
}
print "#list chatlines ins -1 {$line};";
print "#list chatlines del 1;";
print LOG "#list chatlines ins -1 {$line};";
print LOG "#list chatlines del 1;";
print LOG "\n";
$lineStart += length($line);
}
|
|
|